FLTK logo

[master] bdf615d - Fl_GIF_Image: fix potential OOB access

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Library      Forums      Links      Apps     Login 
[  All Forums  |  Back to fltk.commit  ]
 
[ Previous Message ] [ Next Message ]

[master] bdf615d - Fl_GIF_Image: fix potential OOB access "wcout" 14:47 Sep 27  
 
commit bdf615d7c36fc67ed0172433c7e8126e20a44db5
Author:     wcout <wcout@users.noreply.github.com>
AuthorDate: Sat Sep 26 09:23:45 2026 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Sun Sep 27 16:36:15 2026 +0200

    Fl_GIF_Image: fix potential OOB access
    
    A special crafted GIF with no color tables and LZW initial code size not within [2,8] could try to create a color table larger than allocated.

 src/Fl_GIF_Image.cxx | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git src/Fl_GIF_Image.cxx src/Fl_GIF_Image.cxx
index 93fe22f..7217677 100644
--- src/Fl_GIF_Image.cxx
+++ src/Fl_GIF_Image.cxx
@@ -643,7 +643,7 @@ void Fl_GIF_Image::load_gif_(Fl_Image_Reader &rdr, bool anim/*=false*/)
 
       int CodeSize = rdr.read_byte(); // LZW initial Code Size (increases...)
       CHECK_ERROR
-      if (CodeSize < 2 || CodeSize > 8) { // though invalid, other decoders accept an use it
+      if (CodeSize < 2 || CodeSize > 8) { // though invalid, other decoders accept and use it
         Fl::warning("Fl_GIF_Image: %s invalid LZW-initial code size %d.\n", rdr.name(), CodeSize);
       }
       CodeSize++;
@@ -656,6 +656,8 @@ void Fl_GIF_Image::load_gif_(Fl_Image_Reader &rdr, bool anim/*=false*/)
         Fl::warning("%s does not have a color table, using default.\n", rdr.name());
         BitsPerPixel = CodeSize - 1;
         ColorMapSize = 1 << BitsPerPixel;
+        // If LZW inital Code Size was not [2,8] ColorMapSize is out of bounds
+        if (ColorMapSize < 2 || ColorMapSize > 256) ColorMapSize = 2; // invalid: use minimum
         CMap.Red[0] = CMap.Green[0] = CMap.Blue[0] = 0;    // black
         CMap.Red[1] = CMap.Green[1] = CMap.Blue[1] = 255;  // white
         for (int i = 2; i < ColorMapSize; i++) {
[ Direct Link to Message ]
 
     
[ Previous Message ] [ Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2026 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.