mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Skip commands that have too few arguments
- Commands that have too few args will be skipped - Commands that have too many args will generate an info, but still execute
This commit is contained in:
parent
4fa82683fa
commit
5ab3bb1e03
5 changed files with 297 additions and 91 deletions
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
*.pdf
|
||||
|
||||
!tracemonkey.pdf
|
||||
!issue2391-1.pdf
|
||||
!ArabicCIDTrueType.pdf
|
||||
!ThuluthFeatures.pdf
|
||||
!arial_unicode_ab_cidfont.pdf
|
||||
|
|
131
test/pdfs/issue2391-1.pdf
Normal file
131
test/pdfs/issue2391-1.pdf
Normal file
|
@ -0,0 +1,131 @@
|
|||
%PDF-1.4
|
||||
%âãÏÓ
|
||||
1 0 obj
|
||||
<<
|
||||
/Pages 2 0 R
|
||||
/Metadata 3 0 R
|
||||
/Type /Catalog
|
||||
>>
|
||||
endobj
|
||||
2 0 obj
|
||||
<<
|
||||
/Kids [4 0 R]
|
||||
/Count 1
|
||||
/Type /Pages
|
||||
>>
|
||||
endobj
|
||||
4 0 obj
|
||||
<<
|
||||
/Rotate 0
|
||||
/Parent 2 0 R
|
||||
/Resources
|
||||
<<
|
||||
/ExtGState 5 0 R
|
||||
/Font 6 0 R
|
||||
/ProcSet [/PDF /Text]
|
||||
>>
|
||||
/MediaBox [0 0 595 842]
|
||||
/Contents 7 0 R
|
||||
/Type /Page
|
||||
>>
|
||||
endobj
|
||||
7 0 obj
|
||||
<<
|
||||
/Length 148
|
||||
>>
|
||||
stream
|
||||
q 0.1 0 0 0.1 0 0 cm
|
||||
/R7 gs
|
||||
0 g
|
||||
q
|
||||
10 0 0 10 0 0 cm BT
|
||||
undefined 10 Tf
|
||||
/R8 10 Tf
|
||||
1 0 0 1 29 805 Tm
|
||||
(test command with wrong number of args)Tj
|
||||
ET
|
||||
Q
|
||||
Q
|
||||
|
||||
endstream
|
||||
endobj
|
||||
8 0 obj
|
||||
<<
|
||||
/Type /ExtGState
|
||||
/OPM 1
|
||||
>>
|
||||
endobj
|
||||
9 0 obj
|
||||
<<
|
||||
/BaseFont /Courier
|
||||
/Subtype /Type1
|
||||
/Type /Font
|
||||
>>
|
||||
endobj
|
||||
5 0 obj
|
||||
<<
|
||||
/R7 8 0 R
|
||||
>>
|
||||
endobj
|
||||
6 0 obj
|
||||
<<
|
||||
/R8 9 0 R
|
||||
>>
|
||||
endobj
|
||||
3 0 obj
|
||||
<<
|
||||
/Subtype /XML
|
||||
/Length 1421
|
||||
/Type /Metadata
|
||||
>>
|
||||
stream
|
||||
<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
|
||||
<?adobe-xap-filters esc="CRLF"?>
|
||||
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='XMP toolkit 2.9.1-13, framework 1.6'>
|
||||
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:iX='http://ns.adobe.com/iX/1.0/'>
|
||||
<rdf:Description rdf:about='uuid:39048ebf-93ad-11ed-0000-3d9120169d5e' xmlns:pdf='http://ns.adobe.com/pdf/1.3/' pdf:Producer='GPL Ghostscript 9.05'/>
|
||||
<rdf:Description rdf:about='uuid:39048ebf-93ad-11ed-0000-3d9120169d5e' xmlns:xmp='http://ns.adobe.com/xap/1.0/'><xmp:ModifyDate>2013-01-10T17:46:10-08:00</xmp:ModifyDate>
|
||||
<xmp:CreateDate>2013-01-10T17:46:10-08:00</xmp:CreateDate>
|
||||
<xmp:CreatorTool>GNU Enscript 1.6.6</xmp:CreatorTool></rdf:Description>
|
||||
<rdf:Description rdf:about='uuid:39048ebf-93ad-11ed-0000-3d9120169d5e' xmlns:xapMM='http://ns.adobe.com/xap/1.0/mm/' xapMM:DocumentID='uuid:39048ebf-93ad-11ed-0000-3d9120169d5e'/>
|
||||
<rdf:Description rdf:about='uuid:39048ebf-93ad-11ed-0000-3d9120169d5e' xmlns:dc='http://purl.org/dc/elements/1.1/' dc:format='application/pdf'><dc:title><rdf:Alt><rdf:li xml:lang='x-default'>Enscript Output</rdf:li></rdf:Alt></dc:title><dc:creator><rdf:Seq><rdf:li>Mack Duan</rdf:li></rdf:Seq></dc:creator></rdf:Description>
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>
|
||||
|
||||
|
||||
<?xpacket end='w'?>
|
||||
endstream
|
||||
endobj
|
||||
10 0 obj
|
||||
<<
|
||||
/Creator (GNU Enscript 1.6.6)
|
||||
/Title (Enscript Output)
|
||||
/Producer (GPL Ghostscript 9.05)
|
||||
/Author (Mack Duan)
|
||||
/ModDate (D:20130110174610-08'00')
|
||||
/CreationDate (D:20130110174610-08'00')
|
||||
>>
|
||||
endobj xref
|
||||
0 11
|
||||
0000000000 65535 f
|
||||
0000000015 00000 n
|
||||
0000000082 00000 n
|
||||
0000000694 00000 n
|
||||
0000000141 00000 n
|
||||
0000000628 00000 n
|
||||
0000000661 00000 n
|
||||
0000000309 00000 n
|
||||
0000000511 00000 n
|
||||
0000000558 00000 n
|
||||
0000002200 00000 n
|
||||
trailer
|
||||
|
||||
<<
|
||||
/Info 10 0 R
|
||||
/Root 1 0 R
|
||||
/Size 11
|
||||
/ID [<5807376a23851d4cc6096009432892a3> <5807376a23851d4cc6096009432892a3>]
|
||||
>>
|
||||
startxref
|
||||
2406
|
||||
%%EOF
|
|
@ -17,6 +17,13 @@
|
|||
"rounds": 1,
|
||||
"type": "text"
|
||||
},
|
||||
{ "id": "issue2391-1",
|
||||
"file": "pdfs/issue2391-1.pdf",
|
||||
"md5": "25ae9cb959612e7b343b55da63af2716",
|
||||
"rounds": 1,
|
||||
"pageLimit": 1,
|
||||
"type": "load"
|
||||
},
|
||||
{ "id": "html5-canvas-cheat-sheet-load",
|
||||
"file": "pdfs/canvas.pdf",
|
||||
"md5": "59510028561daf62e00bf9f6f066b033",
|
||||
|
|
|
@ -32,13 +32,12 @@ describe('evaluator', function() {
|
|||
var evaluator = new PartialEvaluator(new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('qTT');
|
||||
var thrown = false;
|
||||
try {
|
||||
evaluator.getOperatorList(stream, new ResourcesMock(), []);
|
||||
} catch (e) {
|
||||
thrown = e;
|
||||
}
|
||||
expect(thrown).toNotEqual(false);
|
||||
var result = evaluator.getOperatorList(stream, new ResourcesMock(), []);
|
||||
|
||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||
expect(result.fnArray.length).toEqual(1);
|
||||
expect(result.fnArray[0]).toEqual('save');
|
||||
expect(result.argsArray[0].length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should handle one operations', function() {
|
||||
|
@ -84,14 +83,14 @@ describe('evaluator', function() {
|
|||
'prefix');
|
||||
var resources = new ResourcesMock();
|
||||
resources.Res1 = {};
|
||||
var stream = new StringStream('B*BBMC');
|
||||
var stream = new StringStream('B*Bf*');
|
||||
var result = evaluator.getOperatorList(stream, resources, []);
|
||||
|
||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||
expect(result.fnArray.length).toEqual(3);
|
||||
expect(result.fnArray[0]).toEqual('eoFillStroke');
|
||||
expect(result.fnArray[1]).toEqual('fillStroke');
|
||||
expect(result.fnArray[2]).toEqual('beginMarkedContent');
|
||||
expect(result.fnArray[2]).toEqual('eoFill');
|
||||
});
|
||||
|
||||
it('should handle glued operations and operands', function() {
|
||||
|
@ -112,19 +111,53 @@ describe('evaluator', function() {
|
|||
it('should handle glued operations and literals', function() {
|
||||
var evaluator = new PartialEvaluator(new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('trueifalserinulli');
|
||||
var stream = new StringStream('trueifalserinullq');
|
||||
var result = evaluator.getOperatorList(stream, new ResourcesMock(), []);
|
||||
|
||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||
expect(result.fnArray.length).toEqual(3);
|
||||
expect(result.fnArray[0]).toEqual('setFlatness');
|
||||
expect(result.fnArray[1]).toEqual('setRenderingIntent');
|
||||
expect(result.fnArray[2]).toEqual('setFlatness');
|
||||
expect(result.fnArray[2]).toEqual('save');
|
||||
expect(result.argsArray.length).toEqual(3);
|
||||
expect(result.argsArray[0].length).toEqual(1);
|
||||
expect(result.argsArray[0][0]).toEqual(true);
|
||||
expect(result.argsArray[1].length).toEqual(1);
|
||||
expect(result.argsArray[1][0]).toEqual(false);
|
||||
expect(result.argsArray[2].length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateNumberOfArgs', function() {
|
||||
it('should execute if correct number of arguments', function() {
|
||||
var evaluator = new PartialEvaluator(new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('5 1 d0');
|
||||
var result = evaluator.getOperatorList(stream, new ResourcesMock(), []);
|
||||
|
||||
expect(result.argsArray[0][0]).toEqual(5);
|
||||
expect(result.argsArray[0][1]).toEqual(1);
|
||||
expect(result.fnArray[0]).toEqual('setCharWidth');
|
||||
});
|
||||
it('should execute if too many arguments', function() {
|
||||
var evaluator = new PartialEvaluator(new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('5 1 4 d0');
|
||||
var result = evaluator.getOperatorList(stream, new ResourcesMock(), []);
|
||||
|
||||
expect(result.argsArray[0][0]).toEqual(5);
|
||||
expect(result.argsArray[0][1]).toEqual(1);
|
||||
expect(result.argsArray[0][2]).toEqual(4);
|
||||
expect(result.fnArray[0]).toEqual('setCharWidth');
|
||||
});
|
||||
it('should skip if too few arguments', function() {
|
||||
var evaluator = new PartialEvaluator(new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('5 d0');
|
||||
var result = evaluator.getOperatorList(stream, new ResourcesMock(), []);
|
||||
|
||||
expect(result.argsArray).toEqual([]);
|
||||
expect(result.fnArray).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue