You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/10/12 01:30:40 UTC

svn commit: r312979 - /directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/ber/Asn1Decoder.java

Author: elecharny
Date: Tue Oct 11 16:30:35 2005
New Revision: 312979

URL: http://svn.apache.org/viewcvs?rev=312979&view=rev
Log:
Fixed a big bug in the decoding of TLVs. When a constructed TLV with a zero length value
was encountered, the decoder was loosing its head...

Modified:
    directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/ber/Asn1Decoder.java

Modified: directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/ber/Asn1Decoder.java
URL: http://svn.apache.org/viewcvs/directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/ber/Asn1Decoder.java?rev=312979&r1=312978&r2=312979&view=diff
==============================================================================
--- directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/ber/Asn1Decoder.java (original)
+++ directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/ber/Asn1Decoder.java Tue Oct 11 16:30:35 2005
@@ -521,14 +521,39 @@
                 // one. 
                 // In this case, we have to switch from this parent TLV
                 // to the parent's parent TLV.
-                if (tlv.getTag().isConstructed())
+                if ( tlv.getTag().isConstructed() )
                 {
-                    // It's a constructed TLV. We will set it's parent to the 
-                    // parentTLV, and it will become the new parent TLV, after
-                    // having set the new expected length.
-                    tlv.setParent(parentTLV);
-                    tlv.setExpectedLength(tlv.getLength().getLength());
-                    container.setParentTLV(tlv);
+                    // here, we also have another special case : a 
+                    // zero length TLV. We must then unstack all 
+                    // the parents which length is null.
+                    if ( tlv.getLength().getLength() == 0 )
+                    {
+                        // We will set the parent to the first parentTLV which expectedLength 
+                        // is not null, and it will become the new parent TLV
+                        while ( parentTLV != null )
+                        {
+                            if ( parentTLV.getExpectedLength() != 0 )
+                            {
+                                // ok, we have an incomplete parent. we will
+                                // stop the recursion right here
+                                break;
+                            }
+                            else
+                            {
+                                parentTLV = parentTLV.getParent();
+                            }
+                        }
+
+                        container.setParentTLV(parentTLV);
+                    }
+                    else
+                    {
+                        // The new Parent TLV is this Constructed TLV
+                        container.setParentTLV( tlv );
+                    }
+
+                    tlv.setParent( parentTLV );
+                    tlv.setExpectedLength( tlv.getLength().getLength() );
                 }
                 else
                 {
@@ -563,7 +588,6 @@
 	            {
 	                // We have a constructed tag, so we must switch the parentTLV
                     tlv.setParent(parentTLV);
-                    tlv.setExpectedLength(tlv.getLength().getLength());
                     container.setParentTLV(tlv);
 	            }
             }