← Back to team overview

kicad-developers team mailing list archive

[PATCH] Fix off-by-one in saving bitmaps

 

As per the PNG format specification, the picture file ends with a IEND
chunk which is constant with the following sequence:

 00 00 00 00 49 45 4E 44 AE 42 60 82
|   length  |  "IEND"   |    CRC    |

Any byte beyond this sequence is not part of PNG.

When saving bitmaps as PNG, the stream was read one byte more than its
actual width. This resulted in having the last byte of the serialized
stream changing even when the bitmap isn't modified.

Signed-off-by: Jean-Noel Avila <jn.avila@xxxxxxx>
---
 common/class_bitmap_base.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/class_bitmap_base.cpp b/common/class_bitmap_base.cpp
index c563f1fc4..bd5159935 100644
--- a/common/class_bitmap_base.cpp
+++ b/common/class_bitmap_base.cpp
@@ -109,7 +109,7 @@ bool BITMAP_BASE::SaveData( FILE* aFile ) const
         char*           begin  = (char*) buffer->GetBufferStart();
         int             ii;
 
-        for( ii = 0; begin <= buffer->GetBufferEnd(); begin++, ii++ )
+        for( ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
         {
             if( ii >= 32 )
             {
@@ -140,7 +140,7 @@ void BITMAP_BASE::SaveData( wxArrayString& aPngStrings ) const
         char*           begin  = (char*) buffer->GetBufferStart();
         wxString        line;
 
-        for( int ii = 0; begin <= buffer->GetBufferEnd(); begin++, ii++ )
+        for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
         {
             if( ii >= 32 )
             {
-- 
2.10.1.753.gf3b52a7



Follow ups