From fc54891d096b36118befaf5b22dcc70b69a5181a Mon Sep 17 00:00:00 2001
From: brutzman <brutzman@nps.edu>
Date: Sat, 14 Aug 2021 20:00:39 -0700
Subject: [PATCH] check remaining byte array for PDU bundle, might simply
 consist of additional padding

---
 .../nps/moves/dis7/utilities/PduFactory.java  | 26 +++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/edu/nps/moves/dis7/utilities/PduFactory.java b/src/edu/nps/moves/dis7/utilities/PduFactory.java
index 6bbe3c5c72..7cd9c2f420 100644
--- a/src/edu/nps/moves/dis7/utilities/PduFactory.java
+++ b/src/edu/nps/moves/dis7/utilities/PduFactory.java
@@ -1874,6 +1874,32 @@ public class PduFactory
             remaining = Arrays.copyOfRange(data, pduStartPointInData, length);
 
             try {
+                // first check remaining byte array for PDU bundle, might simply consist of additional padding
+                if (remaining.length <= 16)
+                {
+                    // remaining byte array is too short, smallest PDU is DisPduType 48 ARTICULATED_PARTS, size 17 bytes
+                    // TODO trace capability
+//                    System.out.println("pduBundle remaining byte array is too short for another PDU, length=" + remaining.length);
+                    break;
+                }
+                else
+                {
+                    boolean remainingNonZeroDataFound = false;
+                    for (byte nextByte : remaining)
+                    {
+                        if (nextByte != 0)
+                        {
+                            remainingNonZeroDataFound = true;
+                            continue;
+                        }
+                    }
+                    if (!remainingNonZeroDataFound)
+                    {
+                    // TODO trace capability
+//                        System.out.println("pduBundle remaining byte array (length=" + remaining.length + ") is all zeros, ignored");
+                        break;
+                    }
+                }
                 // Decode one PDU
                 pdu = this.createPdu(remaining);
 
-- 
GitLab