mirror of
https://github.com/pocketpy/pocketpy
synced 2026-05-06 10:13:37 +00:00
fix: add overflow guard in mpack_growable_writer_flush resize loop
This commit is contained in:
parent
c624833cfb
commit
baa4c5b836
@ -1164,10 +1164,16 @@ static void mpack_growable_writer_flush(mpack_writer_t* writer, const char* data
|
||||
(int)count, (int)mpack_writer_buffer_left(writer), (int)used, (int)size);
|
||||
|
||||
// grow to fit the data
|
||||
// TODO: this really needs to correctly test for overflow
|
||||
// overflow-guarded resize
|
||||
if (size > SIZE_MAX / 2) {
|
||||
mpack_writer_flag_error(writer, mpack_error_memory);
|
||||
return;
|
||||
}
|
||||
size_t new_size = size * 2;
|
||||
while (new_size < used + count)
|
||||
while (new_size < used + count) {
|
||||
if (new_size > SIZE_MAX / 2) break;
|
||||
new_size *= 2;
|
||||
}
|
||||
|
||||
mpack_log("flush growing buffer size from %i to %i\n", (int)size, (int)new_size);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user