Harden the JPEG EXIF scan against malformed input (closes #11)
check / check (push) Successful in 26s
check / check (push) Successful in 26s
The segment scan behind `backup-metadata --exif` now checks every segment length against the bytes that remain and stops on lengths under 2, so a truncated or corrupt original can neither throw nor loop. A malformed or unparseable EXIF segment is recorded as `imageMetadata.exifError`, and a failure to read the original as `imageMetadataError` in the per-file JSON, instead of the field being silently left out. Tests use short hand-built byte arrays. Model: opus-5-5
This commit is contained in:
@@ -621,5 +621,18 @@ describe("quak backup-metadata", () => {
|
||||
expect(fileMeta.imageMetadata.format).toBe("jpeg");
|
||||
expect(fileMeta.imageMetadata.width).toBe(100);
|
||||
expect(fileMeta.imageMetadata.height).toBe(80);
|
||||
expect(fileMeta.imageMetadataError).toBeUndefined();
|
||||
|
||||
// File 200 has no original on the mock server, so extraction fails
|
||||
// and the reason is recorded instead of the field being left out.
|
||||
const workDir = collDirs.find((d) => d.includes("Work"))!;
|
||||
const failedMeta = JSON.parse(
|
||||
readFileSync(
|
||||
join(outDir, "collections", workDir, "200.json"),
|
||||
"utf-8",
|
||||
),
|
||||
);
|
||||
expect(failedMeta.imageMetadata).toBeUndefined();
|
||||
expect(failedMeta.imageMetadataError).toEqual(expect.any(String));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user