Skip to content

Commit

Permalink
Fixed|libdeng2: Deflating might produce corrupt data
Browse files Browse the repository at this point in the history
The zlib API was used incorrectly to attempt to deflate a block's
data into a fixed-size buffer.
  • Loading branch information
skyjake committed Nov 30, 2012
1 parent f16be0d commit 73c4baf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doomsday/libdeng2/include/de/data/ziparchive.h
Expand Up @@ -81,7 +81,7 @@ namespace de
public:
/**
* Determines whether a File looks like it could be accessed using
* Archive.
* ZipArchive.
*
* @param file File to check.
*
Expand Down
8 changes: 5 additions & 3 deletions doomsday/libdeng2/src/data/ziparchive.cpp
Expand Up @@ -518,9 +518,8 @@ void ZipArchive::operator >> (Writer &to) const
throw DeflateError("ZipArchive::operator >>", "Deflate init failed");
}

deflate(&stream, Z_FINISH);
int result = deflateEnd(&stream);
if(result == Z_OK)
int result = deflate(&stream, Z_FINISH);
if(result == Z_STREAM_END)
{
// Compression was ok.
header.compression = entry.compression = DEFLATED;
Expand All @@ -538,6 +537,9 @@ void ZipArchive::operator >> (Writer &to) const
entry.offset = writer.offset();
writer << FixedByteArray(*entry.data);
}

// Clean up.
deflateEnd(&stream);
}
}

Expand Down

0 comments on commit 73c4baf

Please sign in to comment.