Skip to content

Commit a229914

Browse files
Merge pull request #19693 from Snuffleupagus/writer-fix-md5
Fix the MD5 computation in the `src/core/writer.js` file
2 parents cd4a303 + e6c869c commit a229914

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/core/writer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function computeMD5(filesize, xrefInfo) {
189189
writeString(str, offset, array);
190190
offset += str.length;
191191
}
192-
return bytesToString(calculateMD5(array));
192+
return bytesToString(calculateMD5(array, 0, array.length));
193193
}
194194

195195
function writeXFADataForAcroform(str, changes) {

test/unit/writer_spec.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ import { bytesToString } from "../../src/shared/util.js";
1919
import { StringStream } from "../../src/core/stream.js";
2020

2121
describe("Writer", function () {
22+
beforeAll(function () {
23+
jasmine.clock().install();
24+
jasmine.clock().mockDate(new Date(0));
25+
});
26+
27+
afterAll(function () {
28+
jasmine.clock().uninstall();
29+
});
30+
2231
describe("Incremental update", function () {
2332
it("should update a file with new objects", async function () {
2433
const originalData = new Uint8Array();
@@ -50,7 +59,7 @@ describe("Writer", function () {
5059
"defg\n" +
5160
"789 0 obj\n" +
5261
"<< /Prev 314 /Size 790 /Type /XRef /Index [123 1 456 1 789 1] " +
53-
"/W [1 1 1] /ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)] " +
62+
"/W [1 1 1] /ID [(id) (\xeb\x4b\x2a\xe7\x31\x36\xf0\xcd\x83\x35\x94\x2a\x36\xcf\xaa\xb0)] " +
5463
"/Length 9>> stream\n" +
5564
"\x01\x01\x2d" +
5665
"\x01\x05\x4e" +
@@ -83,7 +92,7 @@ describe("Writer", function () {
8392
"0000000010 00000 n\r\n" +
8493
"trailer\n" +
8594
"<< /Prev 314 /Size 789 " +
86-
"/ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)]>>\n" +
95+
"/ID [(id) (\xeb\x4b\x2a\xe7\x31\x36\xf0\xcd\x83\x35\x94\x2a\x36\xcf\xaa\xb0)]>>\n" +
8796
"startxref\n" +
8897
"10\n" +
8998
"%%EOF\n";
@@ -279,7 +288,7 @@ describe("Writer", function () {
279288
"\nabc\n" +
280289
"789 0 obj\n" +
281290
"<< /Prev 314 /Size 790 /Type /XRef /Index [123 1 456 1 789 1] " +
282-
"/W [1 1 1] /ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)] " +
291+
"/W [1 1 1] /ID [(id) (\x5f\xd1\x43\x8e\xf8\x62\x79\x80\xbb\xd6\xf7\xb6\xd2\xb5\x6f\xd8)] " +
283292
"/Length 9>> stream\n" +
284293
"\x00\x00\x2e" +
285294
"\x01\x01\x4e" +
@@ -311,7 +320,7 @@ describe("Writer", function () {
311320
"0000000005 00000 n\r\n" +
312321
"trailer\n" +
313322
"<< /Prev 314 /Size 789 " +
314-
"/ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)]>>\n" +
323+
"/ID [(id) (\x5f\xd1\x43\x8e\xf8\x62\x79\x80\xbb\xd6\xf7\xb6\xd2\xb5\x6f\xd8)]>>\n" +
315324
"startxref\n" +
316325
"5\n" +
317326
"%%EOF\n";

0 commit comments

Comments
 (0)