save_buffer8: don't read past the source on a partial last word

The 4-byte packing loop read up to 3 bytes beyond src when length was not
a multiple of 4 (ASan heap-buffer-overflow in data test_ss8). Pack byte by
byte into the zeroed backing buffer instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
iceman1001andClaude Opus 5.5 committed 2026-11-09 23:11:57 +07:00
1 parent a6e0cc7f30
commit d25f06d98e
1 file changed
+3 -6
+3 -6
View File
@@ -582,12 +582,9 @@ buffer_savestate_t save_buffer8(uint8_t *src, size_t length) {
buffer_savestate_t bst = {0};
return bst;
}
size_t index = 0;
// Pack the source array into the backing array
for (size_t i = 0; i < length; i += 4) {
savedBuffer[index] = MemLeToUint4byte(src + i);
index++;
// Pack the source array into the backing array, little endian, last word zero padded
for (size_t i = 0; i < length; i++) {
savedBuffer[i / 4] |= (uint32_t)src[i] << ((i % 4) * 8);
}
buffer_savestate_t bst = {