Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0e6828693 |
@@ -45,9 +45,8 @@ export const extractExifFromJpeg = (
|
|||||||
error: `segment length ${len} at byte ${offset} runs past the end of the file`,
|
error: `segment length ${len} at byte ${offset} runs past the end of the file`,
|
||||||
};
|
};
|
||||||
if (marker === 0xe1) {
|
if (marker === 0xe1) {
|
||||||
// APP1 — check for "Exif\0\0" header. A length under 8 cannot hold
|
// APP1 — check for "Exif\0\0" header. A length under 8 has no
|
||||||
// the six-byte header, so the segment is not EXIF; below 6 the
|
// room for it, and the bytes compared would be the next segment's.
|
||||||
// bytes compared would also lie past the segment.
|
|
||||||
if (
|
if (
|
||||||
len >= 8 &&
|
len >= 8 &&
|
||||||
buf[offset + 4] === 0x45 &&
|
buf[offset + 4] === 0x45 &&
|
||||||
|
|||||||
@@ -52,19 +52,12 @@ describe("extractExifFromJpeg", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("ignores an APP1 segment too short to hold the Exif header", () => {
|
it("ignores an APP1 segment too short to hold the Exif header", () => {
|
||||||
// A length under 8 cannot hold the six-byte "Exif\0\0" header, so the
|
// Length 7 leaves room for "Exif\0" only. Without the length check
|
||||||
// segment is not EXIF. This one has length 7 and holds only "Exif\0",
|
// the scan compared the header against bytes past the segment.
|
||||||
// which the old code, lacking the length check, returned as EXIF.
|
|
||||||
const short = app1(EXIF_HEADER.slice(0, 5));
|
const short = app1(EXIF_HEADER.slice(0, 5));
|
||||||
expect(extractExifFromJpeg(bytes(SOI, short, SOS))).toEqual({});
|
expect(extractExifFromJpeg(bytes(SOI, short, SOS))).toEqual({});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("accepts an APP1 segment of length 8 holding just the Exif header", () => {
|
|
||||||
const scan = extractExifFromJpeg(bytes(SOI, app1(EXIF_HEADER), SOS));
|
|
||||||
expect(scan.error).toBeUndefined();
|
|
||||||
expect([...scan.exif!]).toEqual(EXIF_HEADER);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("reports a JPEG truncated inside a segment header", () => {
|
it("reports a JPEG truncated inside a segment header", () => {
|
||||||
const scan = extractExifFromJpeg(bytes(SOI, [0xff, 0xe1, 0x00]));
|
const scan = extractExifFromJpeg(bytes(SOI, [0xff, 0xe1, 0x00]));
|
||||||
expect(scan.exif).toBeUndefined();
|
expect(scan.exif).toBeUndefined();
|
||||||
|
|||||||
Reference in New Issue
Block a user