mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
refactor(image4): share header result construction (#17053)
This commit is contained in:
1 parent
383f52b3eb
commit
01f4bf79c0
1 file changed
+11
-17
+11
-17
@@ -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,
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user