refactor(image4): share header result construction (#17053)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-05 19:44:52 +08:00
1 parent 383f52b3eb
commit 01f4bf79c0
1 file changed
+11 -17
+11 -17
View File
@@ -354,18 +354,10 @@ const readHeader = async (
return berFailure(cause, offset);
}
const contentStart = offset + header.headerLength;
if (header.length === null)
return {
...header,
indefinite: true,
start: offset,
contentStart,
contentEnd: limit,
end: limit,
nonMinimal: false,
};
const contentEnd = contentStart + header.length;
if (!Number.isSafeInteger(contentEnd) || contentEnd > limit)
const length = header.length;
const indefinite = length === null;
const contentEnd = indefinite ? limit : contentStart + length;
if (!indefinite && (!Number.isSafeInteger(contentEnd) || contentEnd > limit))
throw truncatedInput(
FORMAT,
`Image4 value at offset ${offset} extends past its parent.`,
@@ -373,15 +365,17 @@ const readHeader = async (
);
return {
...header,
indefinite: false,
indefinite,
start: offset,
contentStart,
contentEnd,
end: contentEnd,
nonMinimal: nonMinimalLengthOctets(
header.headerLength - header.identifierLength,
header.length,
),
nonMinimal:
!indefinite &&
nonMinimalLengthOctets(
header.headerLength - header.identifierLength,
length,
),
};
};