Skip to content

Commit ed0038e

Browse files
pavel-alayiText-CI
authored andcommitted
DataMatrix: check array bounds
DEVSIX-1845 Autoported commit. Original commit hash: [87676a67d]
1 parent e64b253 commit ed0038e

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

itext.tests/itext.barcodes.tests/itext/barcodes/BarcodeDataMatrixTest.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,41 @@ public virtual void Barcode10Test() {
213213
int result = barcodeDataMatrix.SetCode("AbcdFFghijklmnopqrstuWXSQ");
214214
NUnit.Framework.Assert.AreEqual(BarcodeDataMatrix.DM_ERROR_TEXT_TOO_BIG, result);
215215
}
216+
217+
[NUnit.Framework.Test]
218+
public virtual void Barcode11Test() {
219+
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
220+
barcodeDataMatrix.SetWidth(18);
221+
barcodeDataMatrix.SetHeight(18);
222+
byte[] str = "AbcdFFghijklmnop".GetBytes();
223+
int result = barcodeDataMatrix.SetCode(str, 0, str.Length);
224+
NUnit.Framework.Assert.AreEqual(BarcodeDataMatrix.DM_NO_ERROR, result);
225+
}
226+
227+
[NUnit.Framework.Test]
228+
public virtual void Barcode12Test() {
229+
NUnit.Framework.Assert.That(() => {
230+
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
231+
barcodeDataMatrix.SetWidth(18);
232+
barcodeDataMatrix.SetHeight(18);
233+
byte[] str = "AbcdFFghijklmnop".GetBytes();
234+
barcodeDataMatrix.SetCode(str, -1, str.Length);
235+
}
236+
, NUnit.Framework.Throws.TypeOf<IndexOutOfRangeException>());
237+
;
238+
}
239+
240+
[NUnit.Framework.Test]
241+
public virtual void Barcode13Test() {
242+
NUnit.Framework.Assert.That(() => {
243+
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
244+
barcodeDataMatrix.SetWidth(18);
245+
barcodeDataMatrix.SetHeight(18);
246+
byte[] str = "AbcdFFghijklmnop".GetBytes();
247+
barcodeDataMatrix.SetCode(str, 0, str.Length + 1);
248+
}
249+
, NUnit.Framework.Throws.TypeOf<IndexOutOfRangeException>());
250+
;
251+
}
216252
}
217253
}

itext/itext.barcodes/itext/barcodes/BarcodeDataMatrix.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ public virtual int SetCode(String text) {
257257
/// <CODE>DM_ERROR_EXTENSION</CODE> - an error was while parsing an extension.
258258
/// </returns>
259259
public virtual int SetCode(byte[] text, int textOffset, int textSize) {
260+
if (textOffset < 0) {
261+
throw new IndexOutOfRangeException("" + textOffset);
262+
}
263+
if (textOffset + textSize > text.Length) {
264+
throw new IndexOutOfRangeException("" + textSize);
265+
}
260266
int extCount;
261267
int e;
262268
int k;

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
963e9369a70d97773f9dfa873b56d13e1dd5e411
1+
87676a67d71abfbc51c3bfd903094dcc3e51239c

0 commit comments

Comments
 (0)