Simplify the handling of unsupported/incorrect markers in src/core/jpg.js

- Re-factor the "incorrect encoding" check, since this can be easily achieved using the general `findNextFileMarker` helper function (with a suitable `startPos` argument).

 - Tweak a condition, to make it easier to see that the end of the data has been reached.

 - Add a reference test for issue 1877, since it's what prompted the "incorrect encoding" check.
This commit is contained in:
Jonas Jenwald 2020-01-13 13:32:23 +01:00
parent 3775b711ed
commit 13930e5202
3 changed files with 18 additions and 12 deletions

View File

@ -1031,17 +1031,14 @@ var JpegImage = (function JpegImageClosure() {
break; break;
default: default:
if ( // Could be incorrect encoding -- the last 0xFF byte of the previous
data[offset - 3] === 0xff && // block could have been eaten by the encoder, hence we fallback to
data[offset - 2] >= 0xc0 && // `startPos = offset - 3` when looking for the next valid marker.
data[offset - 2] <= 0xfe const nextFileMarker = findNextFileMarker(
) { data,
// could be incorrect encoding -- last 0xFF byte of the previous /* currentPos = */ offset - 2,
// block was eaten by the encoder /* startPos = */ offset - 3
offset -= 3; );
break;
}
const nextFileMarker = findNextFileMarker(data, offset - 2);
if (nextFileMarker && nextFileMarker.invalid) { if (nextFileMarker && nextFileMarker.invalid) {
warn( warn(
"JpegImage.parse - unexpected data, current marker is: " + "JpegImage.parse - unexpected data, current marker is: " +
@ -1050,7 +1047,7 @@ var JpegImage = (function JpegImageClosure() {
offset = nextFileMarker.offset; offset = nextFileMarker.offset;
break; break;
} }
if (offset > data.length - 2) { if (offset >= data.length - 1) {
warn( warn(
"JpegImage.parse - reached the end of the image data " + "JpegImage.parse - reached the end of the image data " +
"without finding an EOI marker (0xFFD9)." "without finding an EOI marker (0xFFD9)."

View File

@ -0,0 +1 @@
https://web.archive.org/web/20160313045333/http://brianmckenna.org/files/IC-Roy.pdf

View File

@ -2927,6 +2927,14 @@
"link": true, "link": true,
"type": "eq" "type": "eq"
}, },
{ "id": "issue1877",
"file": "pdfs/issue1877.pdf",
"md5": "feac01f414f2e6792e4d3174944622f5",
"rounds": 1,
"link": true,
"lastPage": 1,
"type": "eq"
},
{ "id": "issue7308", { "id": "issue7308",
"file": "pdfs/issue7308.pdf", "file": "pdfs/issue7308.pdf",
"md5": "ba2e23d3af93ac2c634d77ccbe2e79d5", "md5": "ba2e23d3af93ac2c634d77ccbe2e79d5",