Skip to content

Commit

Permalink
Fix overflow area of hash table in palette generation
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaaaa123456789 committed Jan 9, 2022
1 parent 1c4d068 commit 3395882
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Note: releases are listed from latest to oldest.
- Added a missing check for an extremely unlikely memory allocation failure
- Fixed some BMP encoding bugs that could arise under unusual circumstances
- Fixed BMP decoder to accept images that are exactly `0x7fffffff` pixels tall or wide
- Fixed palette generation for images with many similar colors
- Updated the tutorial to use `plum_append_metadata` where relevant
- Some refactorings and minor documentation changes

Expand Down
4 changes: 2 additions & 2 deletions src/palette.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ int plum_convert_colors_to_indexes (uint8_t * restrict destination, const void *
counts[hash] ++;
total ++;
} else {
for (p = hash; counts[p] & 0x80; p ++) {
for (p = hash; counts[p] & 0x80; p = (p + 1) & 0xff) {
index = (p << 3) | 7;
if (colors[index] == color) goto found;
}
if (total >= 0x100) goto done;
index = (p << 3) | 7;
colors[index] = color;
counts[hash] |= 0x80;
counts[p] |= 0x80;
total ++;
}
found:
Expand Down

0 comments on commit 3395882

Please sign in to comment.