fix(flutter): find snapshot headers that a read chunk boundary splits (#2804)
* fix(flutter): find snapshot headers that a read chunk boundary splits Within one chunk the snapshot hash scanner resumes four bytes after each magic, but across chunks it resumed after the whole 52-byte record and dropped the carried bytes. A magic starting 49-51 bytes after a rejected (non-hex) record was therefore lost when its four bytes straddled a read boundary, so the result depended on chunking and a conflicting hash could be omitted while coverage stayed complete. Resume after the magic in both cases. * refactor(flutter): drop the snapshot scanner cursor the fix superseded After a complete record the carried tail is shorter than a magic, and a pending magic has not been processed, so every push can rescan its carried bytes from the start without counting a record twice. Remove the absolute cursor and base offset, and cover sections 49-51 bytes after a rejected record with two-chunk and byte-at-a-time feeds.
This commit is contained in:
@@ -70,6 +70,37 @@ describe("SnapshotHashScanner", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each([49, 50, 51])(
|
||||
"finds a section %i bytes after a rejected record at any chunking",
|
||||
(start) => {
|
||||
// A stray magic whose hash field is not hex, then a real section that
|
||||
// starts inside the stray record's magic-to-hash span.
|
||||
const payload = new Uint8Array(start + 52);
|
||||
payload.set([0xf5, 0xf5, 0xdc, 0xdc], 0);
|
||||
payload.set(
|
||||
realSnapshotSection("65817c30a78bb44c3dc3771876b6010a"),
|
||||
start,
|
||||
);
|
||||
const whole = new SnapshotHashScanner();
|
||||
whole.push(payload);
|
||||
expect(whole.result()).toEqual({
|
||||
capped: false,
|
||||
sources: 1,
|
||||
candidates: ["65817c30a78bb44c3dc3771876b6010a"],
|
||||
});
|
||||
for (let split = 1; split < payload.length; split += 1) {
|
||||
const scanner = new SnapshotHashScanner();
|
||||
scanner.push(payload.subarray(0, split));
|
||||
scanner.push(payload.subarray(split));
|
||||
expect(scanner.result(), `split at ${split}`).toEqual(whole.result());
|
||||
}
|
||||
const bytewise = new SnapshotHashScanner();
|
||||
for (let offset = 0; offset < payload.length; offset += 1)
|
||||
bytewise.push(payload.subarray(offset, offset + 1));
|
||||
expect(bytewise.result()).toEqual(whole.result());
|
||||
},
|
||||
);
|
||||
|
||||
it("ignores a magic without a following hash", () => {
|
||||
const scanner = new SnapshotHashScanner();
|
||||
scanner.push(Uint8Array.from([0xf5, 0xf5, 0xdc, 0xdc, 0xff, 0xff, 0xff]));
|
||||
|
||||
Reference in New Issue
Block a user