charlietangora / gif-h

Simple C++ one-header library for the creation of animated GIFs from image data.
The Unlicense
497 stars 98 forks source link

Fix off-by-one error with treeSplitElt[] and treeSplit[]. #18

Closed oleg-derevenetz closed 4 years ago

oleg-derevenetz commented 4 years ago

According to calculation logic of treeRoot in GifGetClosestPaletteColor(), max treeRoot value may be 255, so sizes of treeSplitElt[] and treeSplit[] in struct GifPalette should be 256, and not 255. Currently there may be an out-of-bounds error when accessing pPal->treeSplitElt[treeRoot] in GifGetClosestPaletteColor() and other places too. Proposed patch fixes this.

oleg-derevenetz commented 4 years ago

@charlietangora Could you please review this? :)

rversteegen commented 4 years ago

This is bug #16, which is also fixed (in the same way) in PR #17, which unsurprisingly wasn't merged because it's mixed in with Qt-specific stuff. You forgot to bump an instance of 255 to 256, see that PR.

This bug was also fixed by @jacobly0, which I incorporated in my fork: https://github.com/rversteegen/gif-h/commit/1616c5f5bff46a646ef49bbd0ee8262d5fa0bcd6