Skip to content

Commit 2da3c49

Browse files
committed
DataMatrix: check negative textSize
DEVSIX-1845
1 parent 87676a6 commit 2da3c49

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

barcodes/src/main/java/com/itextpdf/barcodes/BarcodeDataMatrix.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public int setCode(byte[] text, int textOffset, int textSize) {
342342
if (textOffset < 0) {
343343
throw new IndexOutOfBoundsException("" + textOffset);
344344
}
345-
if (textOffset + textSize > text.length) {
345+
if (textOffset + textSize > text.length || textOffset + textSize < 0) {
346346
throw new IndexOutOfBoundsException("" + textSize);
347347
}
348348
int extCount, e, k, full;

barcodes/src/test/java/com/itextpdf/barcodes/BarcodeDataMatrixTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,14 @@ public void barcode13Test() {
252252
byte[] str = "AbcdFFghijklmnop".getBytes();
253253
barcodeDataMatrix.setCode(str, 0, str.length + 1);
254254
}
255+
256+
@Test
257+
public void barcode14Test() {
258+
junitExpectedException.expect(IndexOutOfBoundsException.class);;
259+
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
260+
barcodeDataMatrix.setWidth(18);
261+
barcodeDataMatrix.setHeight(18);
262+
byte[] str = "AbcdFFghijklmnop".getBytes();
263+
barcodeDataMatrix.setCode(str, 0, -1);
264+
}
255265
}

0 commit comments

Comments
 (0)