When the old format 12-byte BMP header is used, palette entries are 3 bytes each rather than 4 bytes each.
When computing the number of entries, the size of the header must be subtracted before dividing by 3.
The size of the header in this case is 12 which may also be found in the info.hsz field.
Replace the incorrect hard-coded value of 24 with info.hsz (which will be 12 in this case) otherwise the last 12 bytes of the palette ends up being ignored (12 / 3 => the last 4 palette entries) and any references to them read garbage.
When the old format 12-byte BMP header is used, palette entries are 3 bytes each rather than 4 bytes each.
When computing the number of entries, the size of the header must be subtracted before dividing by 3.
The size of the header in this case is 12 which may also be found in the info.hsz field.
Replace the incorrect hard-coded value of 24 with info.hsz (which will be 12 in this case) otherwise the last 12 bytes of the palette ends up being ignored (12 / 3 => the last 4 palette entries) and any references to them read garbage.