Skip to content

Commit

Permalink
Fix zip EOF emulation;
Browse files Browse the repository at this point in the history
To match regular files, the file offset should be allowed to go past the
end of the file, but reads will return 0 bytes.
  • Loading branch information
bjornbytes committed Nov 22, 2023
1 parent 8ac4d71 commit f04a0e6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/modules/filesystem/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,12 @@ static bool zip_read(Archive* archive, Handle* handle, uint8_t* data, size_t siz
zip_node* node = handle->node;
zip_stream* stream = handle->stream;

// EOF
if (handle->offset >= node->uncompressedSize) {
*count = 0;
return true;
}

// Uncompressed reads are a simple memcpy
if (!node->compressed) {
*count = MIN(size, node->uncompressedSize - handle->offset);
Expand All @@ -810,7 +816,7 @@ static bool zip_read(Archive* archive, Handle* handle, uint8_t* data, size_t siz
return true;
}

// If the file was seeked backwards, gotta rewind to the beginning
// If the file seeked backwards, gotta rewind to the beginning
if (stream->outputCursor > handle->offset) {
tinfl_init(&stream->decompressor);
stream->inputCursor = 0;
Expand Down Expand Up @@ -857,7 +863,7 @@ static bool zip_read(Archive* archive, Handle* handle, uint8_t* data, size_t siz
}

static bool zip_seek(Archive* archive, Handle* handle, uint64_t offset) {
handle->offset = MIN(offset, handle->node->uncompressedSize);
handle->offset = offset;
return true;
}

Expand Down

0 comments on commit f04a0e6

Please sign in to comment.