In peekDTag, need to first check for an element close
diff --git a/ndn-cpp/encoding/BinaryXMLDecoder.c b/ndn-cpp/encoding/BinaryXMLDecoder.c
index f5e4928..6a8900a 100644
--- a/ndn-cpp/encoding/BinaryXMLDecoder.c
+++ b/ndn-cpp/encoding/BinaryXMLDecoder.c
@@ -89,7 +89,13 @@
 {
   // Default to 0.
   *gotExpectedTag = 0;
-  
+
+  // First check if it is an element close (which cannot be the expected tag).  
+  if (self->offset >= self->inputLength)
+    return "ndn_BinaryXMLDecoder_readElementClose: read past the end of the input";
+  if (unsafeGetOctet(self) == 0)
+    return 0;
+
   unsigned int type;
   unsigned int value;
   unsigned int saveOffset = self->offset;