mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 06:52:43 +01:00
Fix bzip2 compression of files > 4 GiB
Bzip2's 'avail_in' parameter is declared as an unsigned int, so
assigning a size_t length to it led to silent truncation.
Fixes #2111.
(cherry picked from commit 4a2c948943)
This commit is contained in:
parent
444b921fcb
commit
1a67d4155f
1 changed files with 14 additions and 3 deletions
|
|
@ -325,8 +325,21 @@ struct BzipSink : CompressionSink
|
|||
}
|
||||
|
||||
void write(const unsigned char * data, size_t len) override
|
||||
{
|
||||
/* Bzip2's 'avail_in' parameter is an unsigned int, so we need
|
||||
to split the input into chunks of at most 4 GiB. */
|
||||
while (len) {
|
||||
auto n = std::min((size_t) std::numeric_limits<decltype(strm.avail_in)>::max(), len);
|
||||
writeInternal(data, n);
|
||||
data += n;
|
||||
len -= n;
|
||||
}
|
||||
}
|
||||
|
||||
void writeInternal(const unsigned char * data, size_t len)
|
||||
{
|
||||
assert(!finished);
|
||||
assert(len <= std::numeric_limits<decltype(strm.avail_in)>::max());
|
||||
|
||||
strm.next_in = (char *) data;
|
||||
strm.avail_in = len;
|
||||
|
|
@ -432,8 +445,6 @@ struct BrotliSink : CompressionSink
|
|||
|
||||
void write(const unsigned char * data, size_t len) override
|
||||
{
|
||||
assert(!finished);
|
||||
|
||||
// Don't feed brotli too much at once
|
||||
const size_t CHUNK_SIZE = sizeof(outbuf) << 2;
|
||||
while (len) {
|
||||
|
|
@ -443,7 +454,7 @@ struct BrotliSink : CompressionSink
|
|||
len -= n;
|
||||
}
|
||||
}
|
||||
private:
|
||||
|
||||
void writeInternal(const unsigned char * data, size_t len)
|
||||
{
|
||||
assert(!finished);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue