I think that it should be up to the branch owners to update what is relevant for the work that they are performing.

Alex Karasulu wrote:
Alan,

Could you apply this to the 'rewrite' branch as well?  In general if we make a change to the trunk it would be nice to apply fixes to branches as well.  Don't know if your branch 'ber-decoder' would take it though.

Thanks,
Alex



Subject:
svn commit: r155835 - in incubator/directory/asn1/trunk/ber/src: java/org/apache/asn1/ber/Length.java test/org/apache/asn1/ber/LengthTest.java
From:
adc@apache.org
Date:
Tue, 01 Mar 2005 22:46:34 -0000
To:
directory-cvs@incubator.apache.org
To:
directory-cvs@incubator.apache.org
X-Account-Key:
account2
Return-Path:
<directory-cvs-return-3796-apmail-akarasulu=apache.org@incubator.apache.org>
Received:
from minotaur.apache.org ([209.237.227.194]) by imf04aec.mail.bellsouth.net (InterMail vM.5.01.06.11 201-253-122-130-111-20040605) with SMTP id <20050301224639.YEGK23956.imf04aec.mail.bellsouth.net@minotaur.apache.org> for <aok123@bellsouth.net>; Tue, 1 Mar 2005 17:46:39 -0500
Received:
(qmail 66870 invoked by uid 1761); 1 Mar 2005 22:46:38 -0000
Delivered-To:
akarasulu@locus.apache.org
Received:
(qmail 66839 invoked from network); 1 Mar 2005 22:46:38 -0000
Received:
from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 1 Mar 2005 22:46:38 -0000
Received:
(qmail 11140 invoked by uid 500); 1 Mar 2005 22:46:37 -0000
Delivered-To:
apmail-akarasulu@apache.org
Received:
(qmail 11085 invoked by uid 500); 1 Mar 2005 22:46:36 -0000
Mailing-List:
contact directory-cvs-help@incubator.apache.org; run by ezmlm
Precedence:
bulk
List-Help:
<mailto:directory-cvs-help@incubator.apache.org>
List-Unsubscribe:
<mailto:directory-cvs-unsubscribe@incubator.apache.org>
List-Post:
<mailto:directory-cvs@incubator.apache.org>
List-Id:
<directory-cvs.incubator.apache.org>
Reply-To:
directory-dev@incubator.apache.org
Delivered-To:
mailing list directory-cvs@incubator.apache.org
Received:
(qmail 11071 invoked by uid 99); 1 Mar 2005 22:46:36 -0000
X-ASF-Spam-Status:
No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME
X-Spam-Check-By:
apache.org
Received:
from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 01 Mar 2005 14:46:36 -0800
Received:
(qmail 66781 invoked by uid 65534); 1 Mar 2005 22:46:34 -0000
Message-ID:
<20050301224634.66780.qmail@minotaur.apache.org>
Content-Type:
text/plain; charset="utf-8"
MIME-Version:
1.0
Content-Transfer-Encoding:
quoted-printable
X-Mailer:
svnmailer-1.0.0-dev
X-Virus-Checked:
Checked
X-Spam-Rating:
minotaur.apache.org 1.6.2 0/1000/N

Author: adc
Date: Tue Mar  1 14:46:31 2005
New Revision: 155835

URL: http://svn.apache.org/viewcvs?view=rev&rev=155835
Log:
The Length' s number of bytes must not be 127
http://issues.apache.org/jira/browse/DIRSNICKERS-102

Modified:
    incubator/directory/asn1/trunk/ber/src/java/org/apache/asn1/ber/Length.java
    incubator/directory/asn1/trunk/ber/src/test/org/apache/asn1/ber/LengthTest.java

Modified: incubator/directory/asn1/trunk/ber/src/java/org/apache/asn1/ber/Length.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/trunk/ber/src/java/org/apache/asn1/ber/Length.java?view=diff&r1=155834&r2=155835
==============================================================================
--- incubator/directory/asn1/trunk/ber/src/java/org/apache/asn1/ber/Length.java (original)
+++ incubator/directory/asn1/trunk/ber/src/java/org/apache/asn1/ber/Length.java Tue Mar  1 14:46:31 2005
@@ -32,8 +32,8 @@
 public class Length
 {
     /** used to mark length as indefinate */
-    public static final int INDEFINATE = -2 ;
-    /** used to mark length as undefined */ 
+    public static final int INDEFINITE = -2 ;
+    /** used to mark length as undefined */
     public static final int UNDEFINED = -1 ;
     /** the end long form terminate bit flag mask */
     public static final int END_MASK = 0x80 ;
@@ -44,21 +44,21 @@
     private int numOctets = UNDEFINED ;
     /** whether or not this length has been fixated */
     private boolean isFixated = false ;
-    /** a byte buffer used to collect the arriving length octets */ 
+    /** a byte buffer used to collect the arriving length octets */
     private final ByteBuffer buf = ByteBuffer.allocate( 5 ) ;
 
 
     /**
      * Checks to see if the length has been fixated.
-     * 
+     *
      * @return true if it is fixated, false if not
      */
     public boolean isFixated()
     {
         return isFixated ;
     }
-    
-    
+
+
     /**
      * Clears this tag's data of all bytes and values calculated so all is as it
      * was when this instance was created.
@@ -70,13 +70,13 @@
         numOctets = 1 ;
         buf.clear() ;
     }
-    
-    
+
+
     /**
-     * Fixates the data within this Length calculating all the derived 
+     * Fixates the data within this Length calculating all the derived
      * properties from the existing set of octets.  While fixated octets
      * cannot be added.
-     * 
+     *
      * @throws org.apache.asn1.codec.DecoderException if this Length is invalid
      */
     void fixate() throws DecoderException
@@ -85,37 +85,52 @@
         value = getLength( buf ) ;
         isFixated = true ;
     }
-    
-    
+
+
     /**
      * Adds an octet to this Length component and as a side effect fixates the
      * Length component if all the required length data has arrived.
-     * 
+     *
      * @param octet the 8 bit byte to add
      */
     void add( byte octet ) throws DecoderException
     {
         if ( isFixated )
-        {  
+        {
             throw new IllegalStateException( "data added to fixated length" ) ;
         }
-        
+
         buf.put( octet ) ;
-        
+
         if ( buf.position() == 1 )
         {
-            // if its the long form
-            if ( END_MASK == ( octet & END_MASK ) && ( octet & 0x7F ) > 0 )
+            // if its the long form, but not above 126 octets : (1)111 1111 is not
+        	// allowed : this value is reserved for future extension.
+            if ( END_MASK == ( octet & END_MASK ))
             {
-                // capture number of octets we need to compute length
-                numOctets = octet & 0x7F ;
+            	int typeLength = octet & 0x7F;
+
+            	if (typeLength == 0)
+            	{
+                    numOctets = INDEFINITE;
+                    fixate() ;
+            	}
+            	else if (typeLength == 0x7F)
+            	{
+            		throw new DecoderException( "The number of octets must not be 127 (reserved for future extension) " ) ;
+            	}
+            	else
+            	{
+	                // capture number of octets we need to compute length
+	                numOctets = octet & 0x7F ;
+            	}
             }
-            else 
-            {    
+            else
+            {
                 fixate() ;
             }
         }
-        
+
         /*
          * if we have collected all the octets needed for computing the long
          * form length so we need to calculate the length and just fixate
@@ -125,22 +140,22 @@
             fixate() ;
         }
     }
-    
-    
+
+
     /**
      * Gets the length of the value.
-     * 
+     *
      * @return the length of the value
      */
     public int getLength()
     {
         return value ;
     }
-    
-    
+
+
     /**
      * Gets the number of octets currently in this Length component.
-     * 
+     *
      * @return the number of octets currently within this Length component
      */
     public int size()
@@ -148,10 +163,10 @@
         return buf.position() ;
     }
 
-    
+
     /**
      * Decodes the length of a value for a tlv using the Length field bytes.
-     * 
+     *
      * @param octets the length field bytes in the TLV
      * @return the length of the TLV
      * @throws DecoderException if the precision cannot hold the number
@@ -167,20 +182,20 @@
              */
             throw new DecoderException( "Length number is too large." ) ;
         }
-        
+
         byte octet = octets.get() ;
-        
+
         // if we are using the short form then just return the first octet
         if ( ( octet & END_MASK ) == 0 )
         {
             return octet ;
         }
-        // using the indefinate form
+        // using the indefinite form
         else if ( ( octet & 0x7F ) == 0 )
         {
-            return INDEFINATE ;
+            return INDEFINITE ;
         }
-        
+
         // using the long form so we calculate the length from all octets
         int length = 0 ;
         for ( int ii = octets.remaining(), shift = (ii-1)<<3; ii > 0; ii--, shift -= 8 )
@@ -196,7 +211,7 @@
 //            shift += 8 ;
 //        }
 //        while ( octets.hasRemaining() ) ;
-        
+
         return length ;
     }
 }

Modified: incubator/directory/asn1/trunk/ber/src/test/org/apache/asn1/ber/LengthTest.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/trunk/ber/src/test/org/apache/asn1/ber/LengthTest.java?view=diff&r1=155834&r2=155835
==============================================================================
--- incubator/directory/asn1/trunk/ber/src/test/org/apache/asn1/ber/LengthTest.java (original)
+++ incubator/directory/asn1/trunk/ber/src/test/org/apache/asn1/ber/LengthTest.java Tue Mar  1 14:46:31 2005
@@ -237,4 +237,48 @@
 
         assertEquals( 1, length.getLength() );
     }
+
+    /**
+     * Test that a Length could not begin with a 0xFF byte, which is
+     * reserved for future extensions.
+     *
+     */
+    public void testRestrictedValueForFutureExtension() 
+    {
+    	Length length = new Length();
+
+        try
+        {
+        	length.add( (byte) 0xFF ) ;
+        	length.add( (byte) 0x01 ) ;
+            fail( "should fail before we get here" ) ;
+        }
+        catch ( DecoderException t )
+        {
+            assertNotNull( t ) ;
+        }
+    }
+
+    /**
+     * Test that an indefinite Length form is rejected. 
+     *
+     */
+    public void testIndefiniteLength() 
+    {
+    	Length length = new Length();
+
+        try
+        {
+        	length.add( (byte) 0x80 ) ;
+        	length.add( (byte) 0x01 ) ;
+        	length.add( (byte) 0x00 ) ;
+        	length.add( (byte) 0x00 ) ;
+            fail( "should fail before we get here" ) ;
+        }
+        catch ( Throwable t )
+        {
+            assertNotNull( t ) ;
+        }
+    }
 }
+