Skip to content

Commit

Permalink
check zlib space to be within buffer #39
Browse files Browse the repository at this point in the history
  • Loading branch information
gdraheim committed Mar 13, 2018
1 parent a825ff3 commit 1ba660b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions zzip/memdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,20 @@ zzip_mem_entry_fopen(ZZIP_MEM_DISK * dir, ZZIP_MEM_ENTRY * entry)
file->zlib.avail_in = zzip_mem_entry_csize(entry);
file->zlib.next_in = zzip_mem_entry_to_data(entry);

debug2("compressed size %i", (int) file->zlib.avail_in);
if (file->zlib.next_in + file->zlib.avail_in >= file->endbuf)
goto error;
if (file->zlib.next_in < file->buffer)
goto error;

if (! zzip_mem_entry_data_deflated(entry) ||
inflateInit2(&file->zlib, -MAX_WBITS) != Z_OK)
{ free (file); return 0; }

return file;
error:
errno = EBADMSG;
return NULL;
}

/** => zzip_mem_entry_open
Expand Down
2 changes: 2 additions & 0 deletions zzip/mmapped.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ zzip_disk_entry_fopen(ZZIP_DISK * disk, ZZIP_DISK_ENTRY * entry)
DBG2("compressed size %i", (int) file->zlib.avail_in);
if (file->zlib.next_in + file->zlib.avail_in >= disk->endbuf)
goto error;
if (file->zlib.next_in < disk->buffer)
goto error;

if (! zzip_file_header_data_deflated(header))
goto error;
Expand Down

0 comments on commit 1ba660b

Please sign in to comment.