Skip to content

Commit

Permalink
Fix padding for >= 2 GiB
Browse files Browse the repository at this point in the history
Previously, the padding was computed by an integer shift, which yielded
wrong results for `msgLen >= 2 GiB`.  It is fixed by using a float
division.

2 GiB and more can be processed when using the File API via a web
worker, so the fix matters in practice.
  • Loading branch information
sprohaska committed Sep 17, 2016
1 parent 06322fd commit 6e1289c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rusha.sweet.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@

var padData = function (bin, chunkLen, msgLen) {
bin[chunkLen>>2] |= 0x80 << (24 - (chunkLen % 4 << 3));
bin[(((chunkLen >> 2) + 2) & ~0x0f) + 14] = msgLen >> 29;
// To support msgLen >= 2 GiB, use a float division when computing the
// high 32-bits of the big-endian message length in bits.
bin[(((chunkLen >> 2) + 2) & ~0x0f) + 14] = (msgLen / (1 << 29)) |0;
bin[(((chunkLen >> 2) + 2) & ~0x0f) + 15] = msgLen << 3;
};

Expand Down

0 comments on commit 6e1289c

Please sign in to comment.