Skip to content

Commit 488cde8

Browse files
committed
gs1process: Avoid inefficient AI parsing
1 parent fa2fd17 commit 488cde8

6 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/gs1-cc.ps.src

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ begin
243243
} if
244244
} if
245245

246+
barcode length 10000 gt { % (90) + numeric capacity (2372) at 4:1 ^NNN parse expansion
247+
/bwipp.gs1ccinputTooLong (The input data is too long) //raiseerror exec
248+
} if
249+
246250
barcode /ai //gs1process exec
247251
/fncs exch def
248252
/vals exch def

src/gs1northamericancoupon.ps.src

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ begin
100100

101101
/barcode exch def
102102

103+
barcode length 300 gt { % (8110) + value (X..70) at 4:1 ^NNN parse expansion
104+
/bwipp.gs1northamericancouponinputTooLong (The input data is too long) //raiseerror exec
105+
} if
106+
103107
/_render
104108
dontdraw /uk.co.terryburton.bwipp.global_ctx dup where {exch get /enabledontdraw known} {pop false} ifelse and
105109
/uk.co.terryburton.bwipp._dontdraw dup where {exch get} {pop false} ifelse or not

src/gs1process.ps.src

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,12 +2376,11 @@ begin
23762376
exch pop exch
23772377
(\() search { exch pop exch } { () } ifelse
23782378
} loop
2379-
counttomark dup 0 gt {dup 2 idiv 1 add -1 exch {-1 roll} for} {pop} ifelse
2380-
counttomark 2 idiv array astore /ais exch def
2381-
counttomark array astore [ exch { % Expand ordinals of the form ^NNN to ASCII
2382-
<< /parse parse /parseonly true /parsefnc false >> //parseinput exec
2383-
} forall ] /vals exch def
2384-
pop
2379+
counttomark array astore exch pop /aivals exch def
2380+
/ais [ 0 2 aivals length 1 sub { aivals exch get } for ] def
2381+
/vals [ 1 2 aivals length 1 sub { % Expand ordinals of the form ^NNN to ASCII
2382+
aivals exch get << /parse parse /parseonly true /parsefnc false >> //parseinput exec
2383+
} for ] def
23852384

23862385
} { % Digital Link URI
23872386

tests/ps_tests/gs1-cc.ps.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
{ () () gs1-cc } /bwipp.GS1aiMissingOpenParen isError
4040
{ () (lintype=upca) gs1-cc } /bwipp.GS1aiMissingOpenParen isError
4141

42+
{ 10001 string () gs1-cc } /bwipp.gs1ccinputTooLong isError
43+
4244
{ ((90)1) (ccversion=d) gs1-cc } /bwipp.gs1ccBadCCversion isError
4345
{ ((90)1) (cccolumns=31) gs1-cc } /bwipp.gs1ccColumnsTooBig isError
4446
{ ((90)1) (cccolumns=0) gs1-cc } /bwipp.gs1ccBadColumns isError

tests/ps_tests/gs1northamericancoupon.ps.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ eq_tmpl_opts
112112
{ ((01)09501101530003) (dontdraw) gs1northamericancoupon } /bwipp.gs1northamericancouponBadAIStructure isError
113113
{ ((8110)7123456789012) (dontdraw dontlint) gs1northamericancoupon } /bwipp.gs1northamericancouponBadVLI isError
114114
{ ((8110)012345) (dontdraw dontlint) gs1northamericancoupon } /bwipp.gs1northamericancouponTooShort isError
115+
{ 301 string (dontdraw) gs1northamericancoupon } /bwipp.gs1northamericancouponinputTooLong isError
115116

116117
% strictspec smoke test
117118
{ 0 0 moveto (\(8110\)106141416543213500110000310123196000) (includetext segments=8 strictspec xdim=0.330) gs1northamericancoupon true } true isEqual

tests/ps_tests/gs1process.ps.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,12 @@
10471047
% Missing close paren in AI
10481048
(\(01) /bwipp.GS1aiMissingCloseParen er_tmpl
10491049

1050+
% Multi-AI parse preserves AI and value order and pairing
1051+
{ ((01)12312312312319(21)ABC123(8030)1) /ai gs1process pop pop }
1052+
[ (01) (21) (8030) ] isEqual
1053+
{ ((01)12312312312319(21)ABC123(8030)1) /ai gs1process pop exch pop }
1054+
[ (12312312312319) (ABC123) (1) ] isEqual
1055+
10501056
% Requisite linting disabled
10511057
/lintreqs false def
10521058
((02)12345678901231) good_tmpl

0 commit comments

Comments
 (0)