fix(managed): report stream-name errors at file offsets (#4418)

Co-authored-by: Mark <m-user@Marks-MacBook-Air.local>
This commit is contained in:
duckhunt113andMark authored and GitHub committed 2026-10-16 23:56:08 +08:00
1 parent 9a82046b07
commit 2d95b85aa4
2 files changed
+80 -3

No files matched your search

+5 -3
View File
@@ -141,8 +141,10 @@ const requireRange = (
const align4 = (value: number): number => Math.ceil(value / 4) * 4;
/** Read within the metadata root; report failures at artifact file offsets. */
const readStreamName = (
bytes: Buffer,
rootOffset: number,
offset: number,
): { readonly name: string; readonly next: number } => {
const endLimit = Math.min(bytes.length, offset + 32);
@@ -153,7 +155,7 @@ const readStreamName = (
"invalid-stream",
"metadata.stream-name",
"Metadata stream name is missing a bounded terminator",
offset,
rootOffset + offset,
);
const nameBytes = bytes.subarray(offset, end);
if (nameBytes.some((byte) => byte < 0x20 || byte > 0x7e))
@@ -161,7 +163,7 @@ const readStreamName = (
"invalid-stream",
"metadata.stream-name",
"Metadata stream name is not printable ASCII",
offset,
rootOffset + offset,
);
return {
name: nameBytes.toString("ascii"),
@@ -250,7 +252,7 @@ const readMetadataStreams = (
requireRange(bytes, rootOffset, cursor, 8, "metadata.stream-header");
const relativeOffset = bytes.readUInt32LE(cursor);
const streamSize = bytes.readUInt32LE(cursor + 4);
const named = readStreamName(bytes, cursor + 8);
const named = readStreamName(bytes, rootOffset, cursor + 8);
if (streams.has(named.name))
throw managedFailure(
"invalid-stream",