fix: Gzip comment with header checksum produces corrupt streams
The Gzip operation manually set the FCOMMENT flag bit after zlibjs had already calculated the header CRC16, corrupting the checksum. Fix by setting options.flags.fcomment before calling compress(), letting zlibjs handle the flag internally. Closes #2243
This commit is contained in:
parent
b0fa1f8d1b
commit
ceeefda024
@ -74,13 +74,11 @@ class Gzip extends Operation {
|
|||||||
}
|
}
|
||||||
if (comment.length) {
|
if (comment.length) {
|
||||||
options.flags.comment = true;
|
options.flags.comment = true;
|
||||||
|
options.flags.fcomment = true;
|
||||||
options.comment = comment;
|
options.comment = comment;
|
||||||
}
|
}
|
||||||
const gzipObj = new Zlib.Gzip(new Uint8Array(input), options);
|
const gzipObj = new Zlib.Gzip(new Uint8Array(input), options);
|
||||||
const compressed = new Uint8Array(gzipObj.compress());
|
const compressed = new Uint8Array(gzipObj.compress());
|
||||||
if (options.flags.comment && !(compressed[3] & 0x10)) {
|
|
||||||
compressed[3] |= 0x10;
|
|
||||||
}
|
|
||||||
return compressed.buffer;
|
return compressed.buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -86,4 +86,64 @@ TestRegister.addTests([
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Gzip: Comment with checksum round-trips through Gunzip",
|
||||||
|
input: "hello hello hello",
|
||||||
|
expectedOutput: "hello hello hello",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Gzip",
|
||||||
|
args: ["Dynamic Huffman Coding", "", "test", true]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "Gunzip",
|
||||||
|
args: []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Gzip: Filename and comment with checksum round-trips through Gunzip",
|
||||||
|
input: "The quick brown fox jumped over the slow dog",
|
||||||
|
expectedOutput: "The quick brown fox jumped over the slow dog",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Gzip",
|
||||||
|
args: ["Dynamic Huffman Coding", "file.txt", "a comment", true]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "Gunzip",
|
||||||
|
args: []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Gzip: No comment, with checksum round-trips through Gunzip",
|
||||||
|
input: "The quick brown fox jumped over the slow dog",
|
||||||
|
expectedOutput: "The quick brown fox jumped over the slow dog",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Gzip",
|
||||||
|
args: ["Dynamic Huffman Coding", "", "", true]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "Gunzip",
|
||||||
|
args: []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Gzip: No options round-trips through Gunzip",
|
||||||
|
input: "The quick brown fox jumped over the slow dog",
|
||||||
|
expectedOutput: "The quick brown fox jumped over the slow dog",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Gzip",
|
||||||
|
args: ["Dynamic Huffman Coding", "", "", false]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "Gunzip",
|
||||||
|
args: []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user