Skip to content

Commit

Permalink
Ensure that callbacks never read/write more bytes than requested
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaaaa123456789 committed Jan 14, 2022
1 parent b891a85 commit b9acaf9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ void load_from_callback (struct context * context, const struct plum_callback *
size_t allocated;
char * buffer = resize_read_buffer(context, NULL, &allocated);
int iteration = callback -> callback(callback -> userdata, buffer, 0x4000 - sizeof(union allocator_node));
if (iteration < 0) throw(context, PLUM_ERR_FILE_ERROR);
if ((iteration < 0) || (iteration > (0x4000 - sizeof(union allocator_node)))) throw(context, PLUM_ERR_FILE_ERROR);
context -> size = iteration;
while (iteration) {
if ((allocated - context -> size) < 0x4000) buffer = resize_read_buffer(context, buffer, &allocated);
iteration = callback -> callback(callback -> userdata, buffer + context -> size, 0x4000);
if (iteration < 0) throw(context, PLUM_ERR_FILE_ERROR);
if ((iteration < 0) || (iteration > 0x4000)) throw(context, PLUM_ERR_FILE_ERROR);
context -> size += iteration;
}
context -> data = buffer;
Expand Down

0 comments on commit b9acaf9

Please sign in to comment.