From 106163936f0ca817deebd3f7ec3fc0bd4bfa4514 Mon Sep 17 00:00:00 2001 From: "T.Elias" Date: Thu, 23 Nov 2023 09:39:59 +0100 Subject: [PATCH 1/4] commit the bug to remote --- .../bertlv/Bug_BERTLVAsciiPackager.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 jpos/src/test/java/org/jpos/tlv/packager/bertlv/Bug_BERTLVAsciiPackager.java diff --git a/jpos/src/test/java/org/jpos/tlv/packager/bertlv/Bug_BERTLVAsciiPackager.java b/jpos/src/test/java/org/jpos/tlv/packager/bertlv/Bug_BERTLVAsciiPackager.java new file mode 100644 index 0000000000..da9d18e14c --- /dev/null +++ b/jpos/src/test/java/org/jpos/tlv/packager/bertlv/Bug_BERTLVAsciiPackager.java @@ -0,0 +1,44 @@ +package org.jpos.tlv.packager.bertlv; +import org.bouncycastle.util.Arrays; +import org.jpos.iso.*; +import org.jpos.tlv.ISOTaggedField; +import org.jpos.tlv.packager.bertlv.BERTLVAsciiHexPackager; +import org.jpos.tlv.packager.bertlv.BERTLVBinaryPackager; + +import org.junit.jupiter.api.*; + +public class Bug_BERTLVAsciiPackager { + + final String HEX_ASCII = "9f2610e18d2a69a45dd09a9f360401839f3708ab34b0bd"; + + @Test + public void testLenInterpretation() throws ISOException { + final ISOMsg ICC_DATA = new ISOMsg(55); + final BERTLVAsciiHexPackager packager = new BERTLVAsciiHexPackager(); + final IFA_LLABINARY fieldPackager = new IFA_LLABINARY(); + + + packager.setFieldPackager(new org.jpos.iso.ISOFieldPackager[]{fieldPackager}); + ICC_DATA.setPackager(packager); + + ICC_DATA.unpack(HEX_ASCII.getBytes()); + + ICC_DATA.getChildren().values().forEach + (e -> { + try { + ISOTaggedField field = (ISOTaggedField) e; + final byte[] value = (byte[]) field.getValue(); + System.out.println("tag " + field.getTag() + " value " + ISOUtil.hexString(value)); + Assertions. + assertFalse(Arrays.isNullOrEmpty(value)); + + } catch (ISOException ex) { + throw new RuntimeException(ex); + } + }); + + + } + +} + From 0ac1f13653aa98511a79f5ac4ba1474e1c04ac20 Mon Sep 17 00:00:00 2001 From: "T.Elias" Date: Thu, 23 Nov 2023 12:10:26 +0100 Subject: [PATCH 2/4] added fix for BERTLVAsciiHexPackager getUninterpretLength bug --- .../main/java/org/jpos/tlv/packager/bertlv/BERTLVPackager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jpos/src/main/java/org/jpos/tlv/packager/bertlv/BERTLVPackager.java b/jpos/src/main/java/org/jpos/tlv/packager/bertlv/BERTLVPackager.java index 05afa7ce98..d0124677f4 100644 --- a/jpos/src/main/java/org/jpos/tlv/packager/bertlv/BERTLVPackager.java +++ b/jpos/src/main/java/org/jpos/tlv/packager/bertlv/BERTLVPackager.java @@ -447,7 +447,7 @@ public void unpack(ISOComponent m, InputStream in) throws IOException, ISOExcept private int getUninterpretLength(int length, BinaryInterpreter interpreter) { if (length > 0) { int lengthAdjusted = length + length % 2; - return length * (lengthAdjusted / interpreter.getPackedLength(lengthAdjusted)); + return (int) (length * (lengthAdjusted / (double) interpreter.getPackedLength(lengthAdjusted))); } return 0; } From 7bc8f09d2611b61a2282a6beaa6335864690f4c5 Mon Sep 17 00:00:00 2001 From: "T.Elias" Date: Thu, 23 Nov 2023 12:15:55 +0100 Subject: [PATCH 3/4] renamed Bug_BERTLVAsciiPackager to Bug568BERTLVAsciiHexPackager --- ...LVAsciiPackager.java => Bug568BERTLVAsciiHexPackager.java} | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) rename jpos/src/test/java/org/jpos/tlv/packager/bertlv/{Bug_BERTLVAsciiPackager.java => Bug568BERTLVAsciiHexPackager.java} (89%) diff --git a/jpos/src/test/java/org/jpos/tlv/packager/bertlv/Bug_BERTLVAsciiPackager.java b/jpos/src/test/java/org/jpos/tlv/packager/bertlv/Bug568BERTLVAsciiHexPackager.java similarity index 89% rename from jpos/src/test/java/org/jpos/tlv/packager/bertlv/Bug_BERTLVAsciiPackager.java rename to jpos/src/test/java/org/jpos/tlv/packager/bertlv/Bug568BERTLVAsciiHexPackager.java index da9d18e14c..6ad3fb5afb 100644 --- a/jpos/src/test/java/org/jpos/tlv/packager/bertlv/Bug_BERTLVAsciiPackager.java +++ b/jpos/src/test/java/org/jpos/tlv/packager/bertlv/Bug568BERTLVAsciiHexPackager.java @@ -2,12 +2,10 @@ import org.bouncycastle.util.Arrays; import org.jpos.iso.*; import org.jpos.tlv.ISOTaggedField; -import org.jpos.tlv.packager.bertlv.BERTLVAsciiHexPackager; -import org.jpos.tlv.packager.bertlv.BERTLVBinaryPackager; import org.junit.jupiter.api.*; -public class Bug_BERTLVAsciiPackager { +public class Bug568BERTLVAsciiHexPackager { final String HEX_ASCII = "9f2610e18d2a69a45dd09a9f360401839f3708ab34b0bd"; From db2842ce5401f4d75dae7e1fbe73ed835be5c5d0 Mon Sep 17 00:00:00 2001 From: "T.Elias" Date: Fri, 24 Nov 2023 01:01:11 +0100 Subject: [PATCH 4/4] applied @barspi solution and changed getUninterpretLength(Integer, Interpeter) --- .../java/org/jpos/tlv/packager/bertlv/BERTLVPackager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jpos/src/main/java/org/jpos/tlv/packager/bertlv/BERTLVPackager.java b/jpos/src/main/java/org/jpos/tlv/packager/bertlv/BERTLVPackager.java index d0124677f4..fdb3738d03 100644 --- a/jpos/src/main/java/org/jpos/tlv/packager/bertlv/BERTLVPackager.java +++ b/jpos/src/main/java/org/jpos/tlv/packager/bertlv/BERTLVPackager.java @@ -447,7 +447,7 @@ public void unpack(ISOComponent m, InputStream in) throws IOException, ISOExcept private int getUninterpretLength(int length, BinaryInterpreter interpreter) { if (length > 0) { int lengthAdjusted = length + length % 2; - return (int) (length * (lengthAdjusted / (double) interpreter.getPackedLength(lengthAdjusted))); + return (length * lengthAdjusted) / interpreter.getPackedLength(lengthAdjusted); } return 0; } @@ -455,7 +455,7 @@ private int getUninterpretLength(int length, BinaryInterpreter interpreter) { private int getUninterpretLength(int length, Interpreter interpreter) { if (length > 0) { int lengthAdjusted = length + length % 2; - return length * (lengthAdjusted / interpreter.getPackedLength(lengthAdjusted)); + return (length * lengthAdjusted) / interpreter.getPackedLength(lengthAdjusted); } return 0; }