Skip to content

Commit

Permalink
Merge pull request #15 from opendesigndev/bugfix/invalid-signature-2
Browse files Browse the repository at this point in the history
catch on invalid signature
  • Loading branch information
alexspevak committed Jan 26, 2023
2 parents 0ced991 + 22415a7 commit d4b8e99
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {parseEngineData, validateSupportedCompression} from "../../methods";
import {
Cursor,
height,
InvalidAdditionalLayerInfoSignature,
InvalidBlendingModeSignature,
MissingRealMaskData,
} from "../../utils";
Expand Down Expand Up @@ -142,7 +143,17 @@ function readLayerRecord(

const additionalLayerInfos: AdditionalLayerInfo[] = [];
while (cursor.position - layerExtraDataBegin < layerExtraDataSize) {
additionalLayerInfos.push(readAdditionalLayerInfo(cursor, fileVersionSpec));
try {
additionalLayerInfos.push(
readAdditionalLayerInfo(cursor, fileVersionSpec)
);
} catch (error) {
if (error instanceof InvalidAdditionalLayerInfoSignature) {
cursor.unpass(4);
break;
}
throw error;
}
}

// Extract useful information from additionalLayerInfos and expose them as
Expand Down Expand Up @@ -206,9 +217,17 @@ export function readGlobalAdditionalLayerInformation(
): AdditionalLayerProperties {
const additionalLayerInfos = [];
while (cursor.position < cursor.length) {
additionalLayerInfos.push(
readAdditionalLayerInfo(cursor, fileVersionSpec, /* padding */ 4)
);
try {
additionalLayerInfos.push(
readAdditionalLayerInfo(cursor, fileVersionSpec, /* padding */ 4)
);
} catch (error) {
if (error instanceof InvalidAdditionalLayerInfoSignature) {
cursor.unpass(4);
break;
}
throw error;
}
}

return fromEntries(
Expand Down

0 comments on commit d4b8e99

Please sign in to comment.