mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 23:58:07 +02:00
Add a MurmurHash3_64.update
unit-test for TypedArrays which share the same underlying ArrayBuffer (PR 12534 follow-up)
This probably ought to have been included in PR 12534, but better late than never I suppose, since it helps to more clearly demonstrate the bug in a way that a reference-test alone just cannot do. When writing this unit-test I also noticed that it required a certain amount of "luck" to actually trigger the bug, prior to the patch, since it seems that the bug only reproduced for certain *unfortunate* sequences of TypedArray data. (The added unit-test contains one such, purposely simple, example.)
This commit is contained in:
parent
ea4d88a330
commit
852c61ef57
1 changed files with 30 additions and 0 deletions
|
@ -60,4 +60,34 @@ describe("MurmurHash3_64", function () {
|
|||
const hexdigest2 = hash.hexdigest();
|
||||
expect(hexdigest1).not.toEqual(hexdigest2);
|
||||
});
|
||||
|
||||
it(
|
||||
"generates correct hashes for TypedArrays which share the same " +
|
||||
"underlying ArrayBuffer (issue 12533)",
|
||||
function () {
|
||||
// prettier-ignore
|
||||
const typedArray = new Uint8Array([
|
||||
0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
|
||||
]);
|
||||
const startArray = new Uint8Array(typedArray.buffer, 0, 10);
|
||||
const endArray = new Uint8Array(typedArray.buffer, 10, 10);
|
||||
|
||||
expect(startArray).not.toEqual(endArray);
|
||||
|
||||
const startHash = new MurmurHash3_64();
|
||||
startHash.update(startArray);
|
||||
const startHexdigest = startHash.hexdigest();
|
||||
|
||||
const endHash = new MurmurHash3_64();
|
||||
endHash.update(endArray);
|
||||
const endHexdigest = endHash.hexdigest();
|
||||
|
||||
// The two hashes *must* be different.
|
||||
expect(startHexdigest).not.toEqual(endHexdigest);
|
||||
|
||||
expect(startHexdigest).toEqual("a49de339cc5b0819");
|
||||
expect(endHexdigest).toEqual("f81a92d9e214ab35");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue