Skip to content

Commit 9727f41

Browse files
committed
Add input validation checks for raw encoding
1 parent 7715221 commit 9727f41

14 files changed

Lines changed: 128 additions & 11 deletions

src/code128.ps.src

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,22 @@ begin
287287
/cws barcode length array def
288288
/i 0 def /j 0 def
289289
{ % loop
290-
i barcode length eq {exit} if
291-
/cw barcode i 1 add 3 getinterval cvi def
290+
i barcode length 3 sub ge {exit} if
291+
barcode i get 94 ne {exit} if
292+
barcode i 1 add 3 getinterval false 1 index {
293+
dup 48 lt exch 57 gt or { pop true } if
294+
} forall { pop exit } if
295+
cvi /cw exch def
296+
cw 106 gt {
297+
/bwipp.code128BadRawCodeword (Raw codewords must be 0 to 106) //raiseerror exec
298+
} if
292299
cws j cw put
293300
/i i 4 add def
294301
/j j 1 add def
295302
} loop
303+
i barcode length ne {
304+
/bwipp.code128BadRawFormat (Raw codewords must be formatted as ^NNN) //raiseerror exec
305+
} if
296306
/cws cws 0 j getinterval def
297307
/text () def
298308
} {

src/code16k.ps.src

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ begin
258258

259259
raw {
260260

261+
/mode 0 def
261262
/cws barcode length array def
262263
/i 0 def /j 0 def
263264
{ % loop
@@ -267,12 +268,15 @@ begin
267268
dup 48 lt exch 57 gt or { pop true } if
268269
} forall { pop exit } if
269270
cvi /cw exch def
271+
cw 106 gt {
272+
/bwipp.code16kBadRawCodeword (Raw codewords must be 0 to 106) //raiseerror exec
273+
} if
270274
cws j cw put
271275
/i i 4 add def
272276
/j j 1 add def
273277
} loop
274278
i barcode length ne {
275-
/bwipp.code16kBadRawFormat (raw data must be formatted as ^NNN) //raiseerror exec
279+
/bwipp.code16kBadRawFormat (Raw codewords must be formatted as ^NNN) //raiseerror exec
276280
} if
277281
/cws cws 0 j getinterval def
278282

src/datamatrix.ps.src

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,22 @@ begin
479479
/cws barcode length array def
480480
/i 0 def /j 0 def
481481
{ % loop
482-
i barcode length eq {exit} if
483-
/cw barcode i 1 add 3 getinterval cvi def
482+
i barcode length 3 sub ge {exit} if
483+
barcode i get 94 ne {exit} if
484+
barcode i 1 add 3 getinterval false 1 index {
485+
dup 48 lt exch 57 gt or { pop true } if
486+
} forall { pop exit } if
487+
cvi /cw exch def
488+
cw 255 gt {
489+
/bwipp.datamatrixBadRawCodeword (Raw codewords must be 0 to 255) //raiseerror exec
490+
} if
484491
cws j cw put
485492
/i i 4 add def
486493
/j j 1 add def
487494
} loop
495+
i barcode length ne {
496+
/bwipp.datamatrixBadRawFormat (Raw codewords must be formatted as ^NNN) //raiseerror exec
497+
} if
488498
/cws cws 0 j getinterval def
489499

490500
} {

src/micropdf417.ps.src

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,12 +672,15 @@ begin
672672
dup 48 lt exch 57 gt or { pop true } if
673673
} forall { pop exit } if
674674
cvi /cw exch def
675+
cw 928 gt {
676+
/bwipp.micropdf417badRawCodeword (Raw codewords must be 0 to 928) //raiseerror exec
677+
} if
675678
datcws j cw put
676679
/i i 4 add def
677680
/j j 1 add def
678681
} loop
679682
i barcode length ne {
680-
/bwipp.micropdf417badCcaRawFormat (cca and raw data must be formatted as ^NNN) //raiseerror exec
683+
/bwipp.micropdf417badCcaRawFormat (Raw codewords must be formatted as ^NNN) //raiseerror exec
681684
} if
682685
/datcws datcws 0 j getinterval def
683686
} if

src/pdf417.ps.src

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,15 @@ begin
586586
dup 48 lt exch 57 gt or { pop true } if
587587
} forall { pop exit } if
588588
cvi /cw exch def
589+
cw 928 gt {
590+
/bwipp.pdf417badRawCodeword (Raw codewords must be 0 to 928) //raiseerror exec
591+
} if
589592
datcws j cw put
590593
/i i 4 add def
591594
/j j 1 add def
592595
} loop
593596
i barcode length ne {
594-
/bwipp.pdf417badRawFormat (raw data must be formatted as ^NNN) //raiseerror exec
597+
/bwipp.pdf417badRawFormat (Raw codewords must be formatted as ^NNN) //raiseerror exec
595598
} if
596599
/datcws datcws 0 j getinterval def
597600
} if

src/posicode.ps.src

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,22 @@ begin
274274
/cws barcode length array def
275275
/i 0 def /j 0 def
276276
{ % loop
277-
i barcode length eq {exit} if
278-
/cw barcode i 1 add 3 getinterval cvi def
277+
i barcode length 3 sub ge {exit} if
278+
barcode i get 94 ne {exit} if
279+
barcode i 1 add 3 getinterval false 1 index {
280+
dup 48 lt exch 57 gt or { pop true } if
281+
} forall { pop exit } if
282+
cvi /cw exch def
283+
cw 45 gt {
284+
/bwipp.posicodeBadRawCodeword (Raw codewords must be 0 to 45) //raiseerror exec
285+
} if
279286
cws j cw put
280287
/i i 4 add def
281288
/j j 1 add def
282289
} loop
290+
i barcode length ne {
291+
/bwipp.posicodeBadRawFormat (Raw codewords must be formatted as ^NNN) //raiseerror exec
292+
} if
283293
/cws cws 0 j getinterval def
284294
/text () def
285295
} if

src/ultracode.ps.src

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,22 @@ begin
275275
/dcws barcode length array def
276276
/i 0 def /j 0 def
277277
{ % loop
278-
i barcode length eq {exit} if
279-
/cw barcode i 1 add 3 getinterval cvi def
278+
i barcode length 3 sub ge {exit} if
279+
barcode i get 94 ne {exit} if
280+
barcode i 1 add 3 getinterval false 1 index {
281+
dup 48 lt exch 57 gt or { pop true } if
282+
} forall { pop exit } if
283+
cvi /cw exch def
284+
cw 284 gt {
285+
/bwipp.ultracodeBadRawCodeword (Raw codewords must be 0 to 284) //raiseerror exec
286+
} if
280287
dcws j cw put
281288
/i i 4 add def
282289
/j j 1 add def
283290
} loop
291+
i barcode length ne {
292+
/bwipp.ultracodeBadRawFormat (Raw codewords must be formatted as ^NNN) //raiseerror exec
293+
} if
284294
/dcws dcws 0 j getinterval def
285295

286296
(input.encoding.raw) //ultracode.after exec

tests/ps_tests/code128.ps.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,14 @@
7878

7979
{ 501 string (dontdraw) code128 } /bwipp.code128inputTooLong isError
8080

81+
% Invalid raw format
82+
{ (^12A) (raw dontdraw) code128 } /bwipp.code128BadRawFormat isError
83+
{ (^12) (raw dontdraw) code128 } /bwipp.code128BadRawFormat isError
84+
{ (^1) (raw dontdraw) code128 } /bwipp.code128BadRawFormat isError
85+
{ (^) (raw dontdraw) code128 } /bwipp.code128BadRawFormat isError
86+
{ (^105garbage) (raw dontdraw) code128 } /bwipp.code128BadRawFormat isError
87+
88+
% Raw codeword out of range (valid: 0-106)
89+
{ (^107) (raw dontdraw) code128 } /bwipp.code128BadRawCodeword isError
90+
{ (^999) (raw dontdraw) code128 } /bwipp.code128BadRawCodeword isError
91+

tests/ps_tests/code16k.ps.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,13 @@
9898

9999
% Invalid raw format
100100
(TEST) (raw dontdraw) /bwipp.code16kBadRawFormat er_tmpl
101+
(^12A) (raw dontdraw) /bwipp.code16kBadRawFormat er_tmpl
102+
(^12) (raw dontdraw) /bwipp.code16kBadRawFormat er_tmpl
103+
(^1) (raw dontdraw) /bwipp.code16kBadRawFormat er_tmpl
104+
(^) (raw dontdraw) /bwipp.code16kBadRawFormat er_tmpl
105+
106+
% Raw codeword out of range (valid: 0-106)
107+
(^107) (raw dontdraw) /bwipp.code16kBadRawCodeword er_tmpl
108+
(^999) (raw dontdraw) /bwipp.code16kBadRawCodeword er_tmpl
101109

102110
501 string (dontdraw) /bwipp.code16kinputTooLong er_tmpl

tests/ps_tests/datamatrix.ps.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,16 @@
130130
(TEST) (version=10xABC dontdraw) /bwipp.datamatrixVersionBadRowOrColumn er_tmpl
131131
(TEST) (version=ABCx10 dontdraw) /bwipp.datamatrixVersionBadRowOrColumn er_tmpl
132132

133+
% Invalid raw format
134+
(^12A) (raw dontdraw) /bwipp.datamatrixBadRawFormat er_tmpl
135+
(^12) (raw dontdraw) /bwipp.datamatrixBadRawFormat er_tmpl
136+
(^1) (raw dontdraw) /bwipp.datamatrixBadRawFormat er_tmpl
137+
(^) (raw dontdraw) /bwipp.datamatrixBadRawFormat er_tmpl
138+
(^230garbage) (raw dontdraw) /bwipp.datamatrixBadRawFormat er_tmpl
139+
140+
% Raw codeword out of range (valid: 0-255)
141+
(^256) (raw dontdraw) /bwipp.datamatrixBadRawCodeword er_tmpl
142+
(^999) (raw dontdraw) /bwipp.datamatrixBadRawCodeword er_tmpl
143+
133144
% Data too long for symbol
134145
(ABCDEFGHIJKLMNOPQRSTUVWXYZ) (version=10x10 dontdraw) /bwipp.datamatrixNoValidSymbol er_tmpl

0 commit comments

Comments
 (0)