This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 010c5cbf029e07d0c73c9e631f926070e999afc5
Author: Sebastian Rühl <sru...@apache.org>
AuthorDate: Thu May 17 15:57:30 2018 +0200

    fixed handling of variable response lengths.
---
 .../java/ads/protocol/util/LittleEndianDecoder.java  | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git 
a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/LittleEndianDecoder.java
 
b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/LittleEndianDecoder.java
index 8394cdf..a68cb7d 100644
--- 
a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/LittleEndianDecoder.java
+++ 
b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/LittleEndianDecoder.java
@@ -51,15 +51,35 @@ public class LittleEndianDecoder {
                 result.add(byteOne);
                 i += 1;
             } else if (datatype == Short.class) {
+                if (length < 2) {
+                    byte[] copy = new byte[2];
+                    System.arraycopy(adsData, 0, copy, 0, length);
+                    adsData = copy;
+                }
                 decodeShort(adsData, i, result);
                 i += 2;
             } else if (datatype == Integer.class) {
+                if (length < 4) {
+                    byte[] copy = new byte[4];
+                    System.arraycopy(adsData, 0, copy, 0, length);
+                    adsData = copy;
+                }
                 decodeInteger(adsData, i, result);
                 i += 4;
             } else if (datatype == Float.class) {
+                if (length < 4) {
+                    byte[] copy = new byte[4];
+                    System.arraycopy(adsData, 0, copy, 0, length);
+                    adsData = copy;
+                }
                 decodeFloat(adsData, i, result);
                 i += 4;
             } else if (datatype == Calendar.class || 
Calendar.class.isAssignableFrom(datatype)) {
+                if (length < 8) {
+                    byte[] copy = new byte[8];
+                    System.arraycopy(adsData, 0, copy, 0, length);
+                    adsData = copy;
+                }
                 extractCalendar(adsData, i, result);
                 i += 8;
             } else {

-- 
To stop receiving notification emails like this one, please contact
sru...@apache.org.

Reply via email to