Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix readvarint32 overflow for normal integer ranges #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Fix varint read overflow in larger number ranges.
Reading varlongs will still fail for larger values
xdnw committed Feb 4, 2024

Unverified

The email in this signature doesn’t match the committer email.
commit 4cf1611642d3f84498556db0fa06597f47bdc8d1
15 changes: 13 additions & 2 deletions dist/bytebuffer.js
Original file line number Diff line number Diff line change
@@ -1578,6 +1578,9 @@
* @expose
*/
ByteBuffer.zigZagDecode32 = function(n) {
if (n > 0x7fffffff) {
return Math.round(Math.floor(n / 2) - (n % 2 != 0 ? 1 : 0));
}
return ((n >>> 1) ^ -(n & 1)) | 0; // // ref: src/google/protobuf/wire_format_lite.h
};

@@ -1665,11 +1668,19 @@
throw err;
}
b = this.view[offset++];
if (c < 5)
if (c < 4) {
value |= (b & 0x7f) << (7*c);
} else if (c < 10) {
let valCopy = Number(value);
value += (b & 0x7f) * Math.pow(2, 7*c);
}
++c;
} while ((b & 0x80) !== 0);
value |= 0;
if (value <= 2147483647) {
value |= 0;
} else {
value = Math.floor(value);
}
if (relative) {
this.offset = offset;
return value;