Skip to content

Commit b951611

Browse files
committed
fix(tasks): guard UTF-8 preview indexing
Keep byte-boundary scanning explicit under unchecked indexed access.
1 parent 48eb552 commit b951611

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

packages/agent-core-v2/src/agent/task/persist.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ interface Utf8TailPreview {
2323
export function utf8TailPreview(data: Uint8Array, maxBytes: number): Utf8TailPreview {
2424
const limit = Math.max(0, Math.trunc(maxBytes));
2525
let start = Math.max(0, data.byteLength - limit);
26-
while (start < data.byteLength && (data[start]! & 0xc0) === 0x80) start += 1;
26+
while (start < data.byteLength) {
27+
const byte = data[start];
28+
if (byte === undefined || (byte & 0xc0) !== 0x80) break;
29+
start += 1;
30+
}
2731
const tail = data.subarray(start);
2832
return { text: textDecoder.decode(tail), bytes: tail.byteLength };
2933
}

0 commit comments

Comments
 (0)