You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Jérôme Baumgarten (JIRA)" <di...@incubator.apache.org> on 2005/09/22 18:07:31 UTC

[jira] Created: (DIRSNICKERS-108) Wrong int encoding in Value

Wrong int encoding in Value
---------------------------

         Key: DIRSNICKERS-108
         URL: http://issues.apache.org/jira/browse/DIRSNICKERS-108
     Project: Directory ASN1
        Type: Bug
  Components: BER Runtime  
    Reporter: Jérôme Baumgarten
 Assigned to: Alex Karasulu 
    Priority: Blocker
 Attachments: Value.patch

Hi,

Encoding is buggy for int value in the org.apache.asn1new.ber.tlv.Value class. The affected methods are :
* public static int getNbBytes( int value )
* public static byte[] getBytes( int value )

Regards,
Jérôme

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DIRSNICKERS-108) Wrong int encoding in Value

Posted by "Jérôme Baumgarten (JIRA)" <di...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/DIRSNICKERS-108?page=comments#action_12330279 ] 

Jérôme Baumgarten commented on DIRSNICKERS-108:
-----------------------------------------------

Regarding decoding of encoded int, there's an easy and straightforward way :

static public int decode(byte[] bytes) {
  return new BigInteger(bytes).intValue();
}

and another way :

  static public int decode(byte[] bytes) {
    int value = 0;
    if ((bytes[0] & 0x80) != 0) {
      // negative value
      value = -1; // 0xFFFFFFFF
    }

    value = (value << 8) | bytes[0];

    for (byte i = 1 ; i < bytes.length ; i++) {
      // The following doesn't work because of the numeric promotion of bytes[i]
      // as explained in section 5.6.2 Binary Numeric Promotion of the
      // Java Language SpecificationThird Edition
      // http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#170983
      // value = (value << 8) | bytes[i];
      value = (value << 8) | (bytes[i] & 0x00FF);
    }
    return value;
  }

Jérôme

> Wrong int encoding in Value
> ---------------------------
>
>          Key: DIRSNICKERS-108
>          URL: http://issues.apache.org/jira/browse/DIRSNICKERS-108
>      Project: Directory ASN1
>         Type: Bug
>   Components: BER Runtime
>     Reporter: Jérôme Baumgarten
>     Assignee: Emmanuel Lecharny
>     Priority: Blocker
>  Attachments: Value.patch
>
> Hi,
> Encoding is buggy for int value in the org.apache.asn1new.ber.tlv.Value class. The affected methods are :
> * public static int getNbBytes( int value )
> * public static byte[] getBytes( int value )
> Regards,
> Jérôme

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DIRSNICKERS-108) Wrong int encoding in Value

Posted by "Jérôme Baumgarten (JIRA)" <di...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/DIRSNICKERS-108?page=comments#action_12330207 ] 

Jérôme Baumgarten commented on DIRSNICKERS-108:
-----------------------------------------------

I actually set it as Blocker because thsi bug affects message ID encoding and after message ID 127, clients (I tested several LDAP clients based on JNDI, JLDAP) seems to be stuck waiting for a response even though the response has been sent.

> Wrong int encoding in Value
> ---------------------------
>
>          Key: DIRSNICKERS-108
>          URL: http://issues.apache.org/jira/browse/DIRSNICKERS-108
>      Project: Directory ASN1
>         Type: Bug
>   Components: BER Runtime
>     Reporter: Jérôme Baumgarten
>     Assignee: Alex Karasulu
>     Priority: Blocker
>  Attachments: Value.patch
>
> Hi,
> Encoding is buggy for int value in the org.apache.asn1new.ber.tlv.Value class. The affected methods are :
> * public static int getNbBytes( int value )
> * public static byte[] getBytes( int value )
> Regards,
> Jérôme

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DIRSNICKERS-108) Wrong int encoding in Value

Posted by "Emmanuel Lecharny (JIRA)" <di...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/DIRSNICKERS-108?page=all ]

Emmanuel Lecharny updated DIRSNICKERS-108:
------------------------------------------

    Priority: Blocker  (was: Major)

I rised the issue as blocker again, because the problem we have occurs in Snickers and Twix.

The encoding of a positive value which high bit is 1 should be totally differnet than the one we obtain :

128 should be encoded as : 0x00 0x80, not 0x80. (ASN.1 BER Encoding)

The encoding of negative value is totally wrong, it seems.

The patch does not resolve those issue, thus it was not applied, except that the idea of substituing textual constant is a really good one and will be applied.

Investigation and tests are still going on.

Thanks Jérôme, for this accurate report !

> Wrong int encoding in Value
> ---------------------------
>
>          Key: DIRSNICKERS-108
>          URL: http://issues.apache.org/jira/browse/DIRSNICKERS-108
>      Project: Directory ASN1
>         Type: Bug
>   Components: BER Runtime
>     Reporter: Jérôme Baumgarten
>     Assignee: Emmanuel Lecharny
>     Priority: Blocker
>  Attachments: Value.patch
>
> Hi,
> Encoding is buggy for int value in the org.apache.asn1new.ber.tlv.Value class. The affected methods are :
> * public static int getNbBytes( int value )
> * public static byte[] getBytes( int value )
> Regards,
> Jérôme

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Resolved: (DIRSNICKERS-108) Wrong int encoding in Value

Posted by "Emmanuel Lecharny (JIRA)" <di...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/DIRSNICKERS-108?page=all ]
     
Emmanuel Lecharny resolved DIRSNICKERS-108:
-------------------------------------------

    Resolution: Fixed

Ok, with huge modifications, this problem has been fixed !

Basically, using previous BER code wrote for Snickers was much easier than trying to bringing back from university all this binary theory I have forgotten ...

It drove me to modify the encoding and decoding of Integer, and had a side effect on Boolean decoding.

Everything should be on track again...

Thanks Jérôme for the sharp reports, and for the time you dedicated on this f****g problem !

btw, using BigInteger is not an option : it's 24x slower than doing it the way Snickers does ;)

WARNING : This is NOT compliant with ASN.1 BER, as the biggest ASN.1 BER integer is supposed to be 256^126 - 1

> Wrong int encoding in Value
> ---------------------------
>
>          Key: DIRSNICKERS-108
>          URL: http://issues.apache.org/jira/browse/DIRSNICKERS-108
>      Project: Directory ASN1
>         Type: Bug
>   Components: BER Runtime
>     Reporter: Jérôme Baumgarten
>     Assignee: Emmanuel Lecharny
>     Priority: Blocker
>  Attachments: Value.patch
>
> Hi,
> Encoding is buggy for int value in the org.apache.asn1new.ber.tlv.Value class. The affected methods are :
> * public static int getNbBytes( int value )
> * public static byte[] getBytes( int value )
> Regards,
> Jérôme

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Assigned: (DIRSNICKERS-108) Wrong int encoding in Value

Posted by "Emmanuel Lecharny (JIRA)" <di...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/DIRSNICKERS-108?page=all ]

Emmanuel Lecharny reassigned DIRSNICKERS-108:
---------------------------------------------

    Assign To: Emmanuel Lecharny  (was: Alex Karasulu)

> Wrong int encoding in Value
> ---------------------------
>
>          Key: DIRSNICKERS-108
>          URL: http://issues.apache.org/jira/browse/DIRSNICKERS-108
>      Project: Directory ASN1
>         Type: Bug
>   Components: BER Runtime
>     Reporter: Jérôme Baumgarten
>     Assignee: Emmanuel Lecharny
>     Priority: Blocker
>  Attachments: Value.patch
>
> Hi,
> Encoding is buggy for int value in the org.apache.asn1new.ber.tlv.Value class. The affected methods are :
> * public static int getNbBytes( int value )
> * public static byte[] getBytes( int value )
> Regards,
> Jérôme

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DIRSNICKERS-108) Wrong int encoding in Value

Posted by "Emmanuel Lecharny (JIRA)" <di...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/DIRSNICKERS-108?page=all ]

Emmanuel Lecharny updated DIRSNICKERS-108:
------------------------------------------

    Priority: Major  (was: Blocker)

I downgraded it to Major, as it affects only the new Codec (Twix), not the current one. But this is definitely a blocking issue if using Twix instead of snickers.

> Wrong int encoding in Value
> ---------------------------
>
>          Key: DIRSNICKERS-108
>          URL: http://issues.apache.org/jira/browse/DIRSNICKERS-108
>      Project: Directory ASN1
>         Type: Bug
>   Components: BER Runtime
>     Reporter: Jérôme Baumgarten
>     Assignee: Emmanuel Lecharny
>  Attachments: Value.patch
>
> Hi,
> Encoding is buggy for int value in the org.apache.asn1new.ber.tlv.Value class. The affected methods are :
> * public static int getNbBytes( int value )
> * public static byte[] getBytes( int value )
> Regards,
> Jérôme

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DIRSNICKERS-108) Wrong int encoding in Value

Posted by "Jérôme Baumgarten (JIRA)" <di...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/DIRSNICKERS-108?page=comments#action_12330263 ] 

Jérôme Baumgarten commented on DIRSNICKERS-108:
-----------------------------------------------

Actually the patch I sent corrects the issue for positive values, I tried it and it does the job for values over 128. I checked it with my LDAP proxy (my running test proxy has served so far 544 messages to the same client / same connection).

I actually tracked that bug down by adding traces to the LdapMessageGrammar class (incoming int values are correctly decoded and 128 is coded as "0x00 0x80" as expected) but the decoding was incorrectly dealing with high bit set to 1, "0x80" was sent back, a value that the clients decode as -128 making it still waiting to the answer to message +128.

Jérôme

> Wrong int encoding in Value
> ---------------------------
>
>          Key: DIRSNICKERS-108
>          URL: http://issues.apache.org/jira/browse/DIRSNICKERS-108
>      Project: Directory ASN1
>         Type: Bug
>   Components: BER Runtime
>     Reporter: Jérôme Baumgarten
>     Assignee: Emmanuel Lecharny
>     Priority: Blocker
>  Attachments: Value.patch
>
> Hi,
> Encoding is buggy for int value in the org.apache.asn1new.ber.tlv.Value class. The affected methods are :
> * public static int getNbBytes( int value )
> * public static byte[] getBytes( int value )
> Regards,
> Jérôme

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DIRSNICKERS-108) Wrong int encoding in Value

Posted by "Jérôme Baumgarten (JIRA)" <di...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/DIRSNICKERS-108?page=all ]

Jérôme Baumgarten updated DIRSNICKERS-108:
------------------------------------------

    Attachment: Value.patch

Attached is a patch to correct the encoding.
I haven't tested it for negative values but it should be ok.

Jérôme

> Wrong int encoding in Value
> ---------------------------
>
>          Key: DIRSNICKERS-108
>          URL: http://issues.apache.org/jira/browse/DIRSNICKERS-108
>      Project: Directory ASN1
>         Type: Bug
>   Components: BER Runtime
>     Reporter: Jérôme Baumgarten
>     Assignee: Alex Karasulu
>     Priority: Blocker
>  Attachments: Value.patch
>
> Hi,
> Encoding is buggy for int value in the org.apache.asn1new.ber.tlv.Value class. The affected methods are :
> * public static int getNbBytes( int value )
> * public static byte[] getBytes( int value )
> Regards,
> Jérôme

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira