mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-09-21 13:31:42 +00:00
fix(worker): read7zNumber throws on first-byte buffer overrun
Prevent silent masking of short reads by validating buffer bounds before
accessing the first byte. Continuation-byte overflow was already caught,
but a short read that leaves pos at/past buffer.length would return {0, pos+1}
instead of throwing, masking the error from callers' try/catch handlers.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -76,6 +76,10 @@ describe("read7zNumber", () => {
|
||||
// 500 = 0x01F4 -> first 0x81, trailing 0xF4
|
||||
expect(read7zNumber(Buffer.from([0x81, 0xf4]), 0)).toEqual({ value: 500, next: 2 });
|
||||
});
|
||||
it("throws when pos starts past the buffer end (short read)", () => {
|
||||
expect(() => read7zNumber(Buffer.from([0x2a]), 5)).toThrow(RangeError);
|
||||
expect(() => read7zNumber(Buffer.alloc(0), 0)).toThrow(RangeError);
|
||||
});
|
||||
});
|
||||
|
||||
describe("locate7zEncodedHeaderPack", () => {
|
||||
|
||||
Reference in New Issue
Block a user