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


The following commit(s) were added to refs/heads/master by this push:
     new 933adbe  fixed digest calculation due to short overflow
933adbe is described below

commit 933adbe4a81dc996427a06c588a88b8aaf287cad
Author: Sebastian Rühl <sru...@apache.org>
AuthorDate: Thu Mar 15 11:45:47 2018 +0100

    fixed digest calculation due to short overflow
---
 .../java/org/apache/plc4x/java/ads/protocol/Ads2SerialProtocol.java  | 5 +++++
 .../java/org/apache/plc4x/java/ads/protocol/util/DigestUtil.java     | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git 
a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Ads2SerialProtocol.java
 
b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Ads2SerialProtocol.java
index 256b4ad..eaeb39d 100644
--- 
a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Ads2SerialProtocol.java
+++ 
b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Ads2SerialProtocol.java
@@ -116,6 +116,11 @@ public class Ads2SerialProtocol extends 
MessageToMessageCodec<ByteBuf, AmsPacket
             throw new PlcProtocolException("CRC checksum wrong");
         }
 
+        if (byteBuf.readableBytes() > 0) {
+            byteBuf.release();
+            throw new IllegalStateException("Unread bytes left: " + 
byteBuf.readableBytes());
+        }
+
         byteBuf.release();
     }
 }
diff --git 
a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/DigestUtil.java
 
b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/DigestUtil.java
index cfed7dd..a813f5c 100644
--- 
a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/DigestUtil.java
+++ 
b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/DigestUtil.java
@@ -37,11 +37,11 @@ public class DigestUtil {
         for (ByteReadable byteReadable : byteReadables) {
             currentCrcValue = crc16.update(currentCrcValue, 
byteReadable.getBytes());
         }
-        return crc16.finalCRC16(currentCrcValue);
+        return crc16.finalCRC16(currentCrcValue) & 0x0000FFFF;
     }
 
     public static int calculateCrc16(byte[] bytes) {
-        return (int) crc16.calculateCRC(bytes);
+        return (int) crc16.calculateCRC(bytes) & 0x0000FFFF;
     }
 
 }

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

Reply via email to