Merge pull request #9730 from Snuffleupagus/jpeg-EOI-decodeScan
Ignore the rest of the image when encountering an EOI (End of Image) marker while parsing Scan data (issue 9679)
This commit is contained in:
		
						commit
						e39541ac18
					
				@ -41,6 +41,18 @@ let DNLMarkerError = (function DNLMarkerErrorClosure() {
 | 
				
			|||||||
  return DNLMarkerError;
 | 
					  return DNLMarkerError;
 | 
				
			||||||
})();
 | 
					})();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					let EOIMarkerError = (function EOIMarkerErrorClosure() {
 | 
				
			||||||
 | 
					  function EOIMarkerError(message) {
 | 
				
			||||||
 | 
					    this.message = message;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  EOIMarkerError.prototype = new Error();
 | 
				
			||||||
 | 
					  EOIMarkerError.prototype.name = 'EOIMarkerError';
 | 
				
			||||||
 | 
					  EOIMarkerError.constructor = EOIMarkerError;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return EOIMarkerError;
 | 
				
			||||||
 | 
					})();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * This code was forked from https://github.com/notmasteryet/jpgjs.
 | 
					 * This code was forked from https://github.com/notmasteryet/jpgjs.
 | 
				
			||||||
 * The original version was created by GitHub user notmasteryet.
 | 
					 * The original version was created by GitHub user notmasteryet.
 | 
				
			||||||
@ -148,6 +160,9 @@ var JpegImage = (function JpegImageClosure() {
 | 
				
			|||||||
              throw new DNLMarkerError(
 | 
					              throw new DNLMarkerError(
 | 
				
			||||||
                'Found DNL marker (0xFFDC) while parsing scan data', scanLines);
 | 
					                'Found DNL marker (0xFFDC) while parsing scan data', scanLines);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					          } else if (nextByte === 0xD9) { // EOI == 0xFFD9
 | 
				
			||||||
 | 
					            throw new EOIMarkerError(
 | 
				
			||||||
 | 
					              'Found EOI marker (0xFFD9) while parsing scan data');
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          throw new JpegError(
 | 
					          throw new JpegError(
 | 
				
			||||||
            `unexpected marker ${((bitsData << 8) | nextByte).toString(16)}`);
 | 
					            `unexpected marker ${((bitsData << 8) | nextByte).toString(16)}`);
 | 
				
			||||||
@ -716,7 +731,7 @@ var JpegImage = (function JpegImageClosure() {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      fileMarker = readUint16();
 | 
					      fileMarker = readUint16();
 | 
				
			||||||
      while (fileMarker !== 0xFFD9) { // EOI (End of image)
 | 
					      markerLoop: while (fileMarker !== 0xFFD9) { // EOI (End of image)
 | 
				
			||||||
        var i, j, l;
 | 
					        var i, j, l;
 | 
				
			||||||
        switch (fileMarker) {
 | 
					        switch (fileMarker) {
 | 
				
			||||||
          case 0xFFE0: // APP0 (Application Specific)
 | 
					          case 0xFFE0: // APP0 (Application Specific)
 | 
				
			||||||
@ -892,9 +907,11 @@ var JpegImage = (function JpegImageClosure() {
 | 
				
			|||||||
              offset += processed;
 | 
					              offset += processed;
 | 
				
			||||||
            } catch (ex) {
 | 
					            } catch (ex) {
 | 
				
			||||||
              if (ex instanceof DNLMarkerError) {
 | 
					              if (ex instanceof DNLMarkerError) {
 | 
				
			||||||
                warn('Attempting to re-parse JPEG image using "scanLines" ' +
 | 
					                warn(`${ex.message} -- attempting to re-parse the JPEG image.`);
 | 
				
			||||||
                     'parameter found in DNL marker (0xFFDC) segment.');
 | 
					 | 
				
			||||||
                return this.parse(data, { dnlScanLines: ex.scanLines, });
 | 
					                return this.parse(data, { dnlScanLines: ex.scanLines, });
 | 
				
			||||||
 | 
					              } else if (ex instanceof EOIMarkerError) {
 | 
				
			||||||
 | 
					                warn(`${ex.message} -- ignoring the rest of the image data.`);
 | 
				
			||||||
 | 
					                break markerLoop;
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
              throw ex;
 | 
					              throw ex;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								test/pdfs/issue9679.pdf.link
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								test/pdfs/issue9679.pdf.link
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					https://github.com/mozilla/pdf.js/files/1929531/K.BIS.PDF
 | 
				
			||||||
@ -3223,6 +3223,13 @@
 | 
				
			|||||||
       "lastPage": 1,
 | 
					       "lastPage": 1,
 | 
				
			||||||
       "type": "eq"
 | 
					       "type": "eq"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    {  "id": "issue9679",
 | 
				
			||||||
 | 
					       "file": "pdfs/issue9679.pdf",
 | 
				
			||||||
 | 
					       "md5": "3077d06add3875705aa1021c7b116023",
 | 
				
			||||||
 | 
					       "rounds": 1,
 | 
				
			||||||
 | 
					       "link": true,
 | 
				
			||||||
 | 
					       "type": "eq"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    {  "id": "bug1108753",
 | 
					    {  "id": "bug1108753",
 | 
				
			||||||
       "file": "pdfs/bug1108753.pdf",
 | 
					       "file": "pdfs/bug1108753.pdf",
 | 
				
			||||||
       "md5": "a7aaf92d55b4602afb0ca3d75198b56b",
 | 
					       "md5": "a7aaf92d55b4602afb0ca3d75198b56b",
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user