aboutsummaryrefslogtreecommitdiffstats
path: root/src/ark/proto.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/ark/proto.js')
-rw-r--r--src/ark/proto.js3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/ark/proto.js b/src/ark/proto.js
index 6729465..81651ee 100644
--- a/src/ark/proto.js
+++ b/src/ark/proto.js
@@ -29,6 +29,9 @@ export function pbWriter() {
const chunks = [];
const varint = (n) => {
n = BigInt(n);
+ // a negative sign-extends under >>= forever — the do/while would push
+ // bytes until the process dies of memory, so refuse it loudly instead
+ if (n < 0n) throw new Error(`varint: negative value ${n}`);
const bs = [];
do { let b = Number(n & 0x7fn); n >>= 7n; if (n) b |= 0x80; bs.push(b); } while (n);
chunks.push(Uint8Array.from(bs));