From directory-dev-return-4650-apmail-incubator-directory-dev-archive=incubator.apache.org@incubator.apache.org Wed Mar 02 00:07:04 2005 Return-Path: Delivered-To: apmail-incubator-directory-dev-archive@www.apache.org Received: (qmail 99385 invoked from network); 2 Mar 2005 00:07:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 2 Mar 2005 00:07:03 -0000 Received: (qmail 29767 invoked by uid 500); 2 Mar 2005 00:07:03 -0000 Delivered-To: apmail-incubator-directory-dev-archive@incubator.apache.org Received: (qmail 29652 invoked by uid 500); 2 Mar 2005 00:07:03 -0000 Mailing-List: contact directory-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list directory-dev@incubator.apache.org Received: (qmail 29623 invoked by uid 99); 2 Mar 2005 00:07:03 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=FROM_ENDS_IN_NUMS X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: 192.215.81.76 is neither permitted nor denied by domain of aok123@bellsouth.net) Received: from relay3.san2.attens.com (HELO relay3.san1.attens.com) (192.215.81.76) by apache.org (qpsmtpd/0.28) with ESMTP; Tue, 01 Mar 2005 16:07:02 -0800 Received: from [192.168.248.94] ([12.104.1.131]) by relay3.san1.attens.com (8.11.6/8.9.3) with ESMTP id j22070916051 for ; Wed, 2 Mar 2005 00:07:00 GMT Message-ID: <42250387.20400@bellsouth.net> Date: Tue, 01 Mar 2005 19:06:31 -0500 From: Alex Karasulu User-Agent: Mozilla Thunderbird 0.9 (X11/20041127) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Apache Directory Developers List Subject: [Fwd: svn commit: r155835 - in incubator/directory/asn1/trunk/ber/src: java/org/apache/asn1/ber/Length.java test/org/apache/asn1/ber/LengthTest.java] Content-Type: multipart/mixed; boundary="------------080907060601090709060001" X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. --------------080907060601090709060001 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------080907060601090709060001 Content-Type: message/rfc822; name="svn commit: r155835 - in incubator/directory/asn1/trunk/ber/src: java/org/apache/asn1/ber/Length.javatest/org/apache/asn1/ber/LengthTest.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="svn commit: r155835 - in incubator/directory/asn1/trunk/ber/src: java/org/apache/asn1/ber/Length.javatest/org/apache/asn1/ber/LengthTest.java" X-Account-Key: account2 Return-Path: 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 ; 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: List-Unsubscribe: List-Post: List-Id: 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 Date: Tue, 01 Mar 2005 22:46:34 -0000 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 To: directory-cvs@incubator.apache.org From: adc@apache.org 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=3Drev&rev=3D155835 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/LengthT= est.java Modified: incubator/directory/asn1/trunk/ber/src/java/org/apache/asn1/ber/L= ength.java URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/trunk/ber/src/j= ava/org/apache/asn1/ber/Length.java?view=3Ddiff&r1=3D155834&r2=3D155835 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- 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 =3D -2 ; - /** used to mark length as undefined */=20 + public static final int INDEFINITE =3D -2 ; + /** used to mark length as undefined */ public static final int UNDEFINED =3D -1 ; /** the end long form terminate bit flag mask */ public static final int END_MASK =3D 0x80 ; @@ -44,21 +44,21 @@ private int numOctets =3D UNDEFINED ; /** whether or not this length has been fixated */ private boolean isFixated =3D false ; - /** a byte buffer used to collect the arriving length octets */=20 + /** a byte buffer used to collect the arriving length octets */ private final ByteBuffer buf =3D ByteBuffer.allocate( 5 ) ; =20 =20 /** * Checks to see if the length has been fixated. - *=20 + * * @return true if it is fixated, false if not */ public boolean isFixated() { return isFixated ; } - =20 - =20 + + /** * 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 =3D 1 ; buf.clear() ; } - =20 - =20 + + /** - * Fixates the data within this Length calculating all the derived=20 + * Fixates the data within this Length calculating all the derived * properties from the existing set of octets. While fixated octets * cannot be added. - *=20 + * * @throws org.apache.asn1.codec.DecoderException if this Length is in= valid */ void fixate() throws DecoderException @@ -85,37 +85,52 @@ value =3D getLength( buf ) ; isFixated =3D true ; } - =20 - =20 + + /** * Adds an octet to this Length component and as a side effect fixates= the * Length component if all the required length data has arrived. - *=20 + * * @param octet the 8 bit byte to add */ void add( byte octet ) throws DecoderException { if ( isFixated ) - { =20 + { throw new IllegalStateException( "data added to fixated length= " ) ; } - =20 + buf.put( octet ) ; - =20 + if ( buf.position() =3D=3D 1 ) { - // if its the long form - if ( END_MASK =3D=3D ( octet & END_MASK ) && ( octet & 0x7F ) = > 0 ) + // if its the long form, but not above 126 octets : (1)111 111= 1 is not + // allowed : this value is reserved for future extension. + if ( END_MASK =3D=3D ( octet & END_MASK )) { - // capture number of octets we need to compute length - numOctets =3D octet & 0x7F ; + int typeLength =3D octet & 0x7F; + + if (typeLength =3D=3D 0) + { + numOctets =3D INDEFINITE; + fixate() ; + } + else if (typeLength =3D=3D 0x7F) + { + throw new DecoderException( "The number of octets must not b= e 127 (reserved for future extension) " ) ; + } + else + { + // capture number of octets we need to compute length + numOctets =3D octet & 0x7F ; + } } - else=20 - { =20 + else + { fixate() ; } } - =20 + /* * if we have collected all the octets needed for computing the lo= ng * form length so we need to calculate the length and just fixate @@ -125,22 +140,22 @@ fixate() ; } } - =20 - =20 + + /** * Gets the length of the value. - *=20 + * * @return the length of the value */ public int getLength() { return value ; } - =20 - =20 + + /** * Gets the number of octets currently in this Length component. - *=20 + * * @return the number of octets currently within this Length component */ public int size() @@ -148,10 +163,10 @@ return buf.position() ; } =20 - =20 + /** * Decodes the length of a value for a tlv using the Length field byte= s=2E - *=20 + * * @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." ) ; } - =20 + byte octet =3D octets.get() ; - =20 + // if we are using the short form then just return the first octet if ( ( octet & END_MASK ) =3D=3D 0 ) { return octet ; } - // using the indefinate form + // using the indefinite form else if ( ( octet & 0x7F ) =3D=3D 0 ) { - return INDEFINATE ; + return INDEFINITE ; } - =20 + // using the long form so we calculate the length from all octets int length =3D 0 ; for ( int ii =3D octets.remaining(), shift =3D (ii-1)<<3; ii > 0; = ii--, shift -=3D 8 ) @@ -196,7 +211,7 @@ // shift +=3D 8 ; // } // while ( octets.hasRemaining() ) ; - =20 + return length ; } } Modified: incubator/directory/asn1/trunk/ber/src/test/org/apache/asn1/ber/L= engthTest.java URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/trunk/ber/src/t= est/org/apache/asn1/ber/LengthTest.java?view=3Ddiff&r1=3D155834&r2=3D155835 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/directory/asn1/trunk/ber/src/test/org/apache/asn1/ber/LengthT= est.java (original) +++ incubator/directory/asn1/trunk/ber/src/test/org/apache/asn1/ber/LengthT= est.java Tue Mar 1 14:46:31 2005 @@ -237,4 +237,48 @@ =20 assertEquals( 1, length.getLength() ); } + + /** + * Test that a Length could not begin with a 0xFF byte, which is + * reserved for future extensions. + * + */ + public void testRestrictedValueForFutureExtension()=20 + { + Length length =3D 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.=20 + * + */ + public void testIndefiniteLength()=20 + { + Length length =3D 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 ) ; + } + } } + --------------080907060601090709060001--