Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function bufferizeInt(num) {
function _crc32(buf, previous) {
buf = ensureBuffer(buf);
if (Buffer.isBuffer(previous)) {
previous = previous.readUInt32BE(0);
previous = previous.length >= 4 ? previous.readUInt32BE(0) : 0;
}
let crc = ~~previous ^ -1;
for (var n = 0; n < buf.length; n++) {
Expand Down
7 changes: 7 additions & 0 deletions tests/crc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,10 @@ test('can do unsigned in append mode', function (t) {
t.same(crc, expected);
t.end();
});

test('no readUInt32BE on small previous buffer', function (t) {
var prev = Buffer.from([0xDE, 0xAD, 0xBE]);
var expected = Buffer.from([0x35, 0x24, 0x41, 0xc2]);
t.same(crc32("abc", ), expected);
t.end();
});