Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Refuse a PNG whose end marker carries data
Claudec1b546333e40
diff --git a/src/lib/brand-logo.test.ts b/src/lib/brand-logo.test.tsindex 80a6cd2..deb9dfa 100644--- a/src/lib/brand-logo.test.ts+++ b/src/lib/brand-logo.test.ts@@ -405,3 +405,14 @@ test("a lossy WebP whose first partition runs past its data is refused", () => {BrandLogoError,);});++test("a PNG whose end marker carries data is refused", () => {+ const png = buildPng({ height: 2, raw: new Uint8Array(18), width: 2 });+ // Swap the empty IEND for one holding a byte.+ const bytes = Buffer.concat([+ png.subarray(0, png.length - 12),+ pngChunk("IEND", Buffer.from([0])),+ ]);++ assert.throws(() => checkLogoUpload(bytes), BrandLogoError);+});diff --git a/src/lib/brand-logo.ts b/src/lib/brand-logo.tsindex 7bf136d..bd735ef 100644--- a/src/lib/brand-logo.ts+++ b/src/lib/brand-logo.ts@@ -248,7 +248,12 @@ function isCompletePng(bytes: Uint8Array): boolean {} else if (type === "IDAT") {data.push(bytes.subarray(dataStart, dataEnd));} else if (type === "IEND") {- if (data.length === 0 || (header.colorType === 3 && !seenPalette)) {+ // The end marker carries nothing.+ if (+ length !== 0 ||+ data.length === 0 ||+ (header.colorType === 3 && !seenPalette)+ ) {return false;}