diff options
| author | jmestwa-coder <jmestwa@gmail.com> | 2026-06-13 16:54:38 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-13 16:54:38 +0300 |
| commit | 36539a1c8eef40c75866016bc3366f036629ece3 (patch) | |
| tree | ac1d47e9afe5471b3da8fbdec8a9fa5ffc9a0b57 /core | |
| parent | 6dc847efc12c2aa0a8c803a0ecd5c93c6e31f170 (diff) | |
| download | zxing-36539a1c8eef40c75866016bc3366f036629ece3.tar.xz | |
guard truncated symbol in rss expanded AI01AndOtherAIs decoder (#2089)
Diffstat (limited to 'core')
| -rw-r--r-- | core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01AndOtherAIs.java | 4 | ||||
| -rw-r--r-- | core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AI01AndOtherAIsTest.java | 37 |
2 files changed, 41 insertions, 0 deletions
diff --git a/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01AndOtherAIs.java b/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01AndOtherAIs.java index 27222a382..a3e5db65d 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01AndOtherAIs.java +++ b/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01AndOtherAIs.java @@ -44,6 +44,10 @@ final class AI01AndOtherAIs extends AI01decoder { @Override public String parseInformation() throws NotFoundException, FormatException { + if (this.getInformation().getSize() < HEADER_SIZE + GTIN_SIZE + 4) { + throw NotFoundException.getNotFoundInstance(); + } + StringBuilder buff = new StringBuilder(); buff.append("(01)"); diff --git a/core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AI01AndOtherAIsTest.java b/core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AI01AndOtherAIsTest.java new file mode 100644 index 000000000..62f811431 --- /dev/null +++ b/core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AI01AndOtherAIsTest.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2010 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.oned.rss.expanded.decoders; + +import com.google.zxing.NotFoundException; +import com.google.zxing.common.BitArray; +import com.google.zxing.oned.rss.expanded.BinaryUtil; + +import org.junit.Test; + +/** + * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) + */ +public final class AI01AndOtherAIsTest extends AbstractDecoderTest { + + // first bit is the linkage flag, second bit selects this decoder + @Test(expected = NotFoundException.class) + public void testTruncatedSymbol() throws Exception { + // 24 bits, too few to hold the compressed GTIN this decoder always reads + BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(".X......................"); + AbstractExpandedDecoder.createDecoder(binary).parseInformation(); + } +} |
