Merge pull request #15897 from Snuffleupagus/issue-15893
Support parsing encrypted documents in `XRef.indexObjects` (issue 15893)
This commit is contained in:
		
						commit
						74e4b515c5
					
				| @ -581,16 +581,11 @@ class XRef { | |||||||
|       this.startXRefQueue.push(xrefStm); |       this.startXRefQueue.push(xrefStm); | ||||||
|       this.readXRef(/* recoveryMode */ true); |       this.readXRef(/* recoveryMode */ true); | ||||||
|     } |     } | ||||||
|     // finding main trailer
 | 
 | ||||||
|     let trailerDict, trailerError; |     const trailerDicts = []; | ||||||
|     for (const trailer of [...trailers, "generationFallback", ...trailers]) { |     // Pre-parsing the trailers to check if the document is possibly encrypted.
 | ||||||
|       if (trailer === "generationFallback") { |     let isEncrypted = false; | ||||||
|         if (!trailerError) { |     for (const trailer of trailers) { | ||||||
|           break; // No need to fallback if there were no validation errors.
 |  | ||||||
|         } |  | ||||||
|         this._generationFallback = true; |  | ||||||
|         continue; |  | ||||||
|       } |  | ||||||
|       stream.pos = trailer; |       stream.pos = trailer; | ||||||
|       const parser = new Parser({ |       const parser = new Parser({ | ||||||
|         lexer: new Lexer(stream), |         lexer: new Lexer(stream), | ||||||
| @ -607,6 +602,23 @@ class XRef { | |||||||
|       if (!(dict instanceof Dict)) { |       if (!(dict instanceof Dict)) { | ||||||
|         continue; |         continue; | ||||||
|       } |       } | ||||||
|  |       trailerDicts.push(dict); | ||||||
|  | 
 | ||||||
|  |       if (dict.has("Encrypt")) { | ||||||
|  |         isEncrypted = true; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // finding main trailer
 | ||||||
|  |     let trailerDict, trailerError; | ||||||
|  |     for (const dict of [...trailerDicts, "genFallback", ...trailerDicts]) { | ||||||
|  |       if (dict === "genFallback") { | ||||||
|  |         if (!trailerError) { | ||||||
|  |           break; // No need to fallback if there were no validation errors.
 | ||||||
|  |         } | ||||||
|  |         this._generationFallback = true; | ||||||
|  |         continue; | ||||||
|  |       } | ||||||
|       // Do some basic validation of the trailer/root dictionary candidate.
 |       // Do some basic validation of the trailer/root dictionary candidate.
 | ||||||
|       let validPagesDict = false; |       let validPagesDict = false; | ||||||
|       try { |       try { | ||||||
| @ -628,7 +640,11 @@ class XRef { | |||||||
|         continue; |         continue; | ||||||
|       } |       } | ||||||
|       // taking the first one with 'ID'
 |       // taking the first one with 'ID'
 | ||||||
|       if (validPagesDict && dict.has("ID")) { |       if ( | ||||||
|  |         validPagesDict && | ||||||
|  |         (!isEncrypted || dict.has("Encrypt")) && | ||||||
|  |         dict.has("ID") | ||||||
|  |       ) { | ||||||
|         return dict; |         return dict; | ||||||
|       } |       } | ||||||
|       // The current dictionary is a candidate, but continue searching.
 |       // The current dictionary is a candidate, but continue searching.
 | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								test/pdfs/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								test/pdfs/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -413,6 +413,7 @@ | |||||||
| !issue2128r.pdf | !issue2128r.pdf | ||||||
| !bug1703683_page2_reduced.pdf | !bug1703683_page2_reduced.pdf | ||||||
| !issue5540.pdf | !issue5540.pdf | ||||||
|  | !issue15893_reduced.pdf | ||||||
| !issue5549.pdf | !issue5549.pdf | ||||||
| !visibility_expressions.pdf | !visibility_expressions.pdf | ||||||
| !issue5475.pdf | !issue5475.pdf | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								test/pdfs/issue15893_reduced.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/pdfs/issue15893_reduced.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -386,6 +386,13 @@ | |||||||
|       "lastPage": 4, |       "lastPage": 4, | ||||||
|       "type": "eq" |       "type": "eq" | ||||||
|     }, |     }, | ||||||
|  |     {  "id": "issue15893_reduced", | ||||||
|  |        "file": "pdfs/issue15893_reduced.pdf", | ||||||
|  |        "md5": "cf889b927f9f53d164622a99378bf39d", | ||||||
|  |        "rounds": 1, | ||||||
|  |        "type": "eq", | ||||||
|  |        "password": "test" | ||||||
|  |     }, | ||||||
|     {  "id": "bug1727053", |     {  "id": "bug1727053", | ||||||
|        "file": "pdfs/bug1727053.pdf", |        "file": "pdfs/bug1727053.pdf", | ||||||
|        "md5": "8ed1e52da64000f9fdcb8b732f5a58f8", |        "md5": "8ed1e52da64000f9fdcb8b732f5a58f8", | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user