dev@fi.java.net

Bugs in Decoder.java

From: Andrzej Gladkowski <agladkowski_at_gmail.com>
Date: Fri, 30 Oct 2009 18:13:07 +0000

Hi All,
The team I work for build the Encoder (C#) and Decoder (in C) and as a
sanity test we decided to check that against
the java fastinfoset implementation.

We believe that we found a number of bugs in the Decoder implementation
testing it with fastinfoset-test.fi (see attachment).
Here is the list of things we found so far:

---------------------------------------------
Decoder.java

Wrong:
...
    private void decodeTableItems(StringArray array) throws
FastInfosetException, IOException {
        for (int i = 0; i < decodeNumberOfItemsOfSequence(); i++) {
            array.add(decodeNonEmptyOctetStringOnSecondBitAsUtf8String());
        }
    }
...
Correct: (See point C.2.5.2 in http://www.itu.int/rec/T-REC-X.891-200505-I)

    private void decodeTableItems(StringArray array) throws
FastInfosetException, IOException {
        int noOfNamespaces = decodeNumberOfItemsOfSequence();
        for (int i = 0; i < noOfNamespaces; i++) {
        array.add(decodeNonEmptyOctetStringOnSecondBitAsUtf8String());
        }
    }


Wrong:
...
    private int decodeNumberOfItemsOfSequence() throws IOException {
        final int b = read();
        if (b < 128) {
            return b;
        } else {
            return ((b & 0x0F) << 16) | (read() << 8) | read();
        }
    }
...
Correct -> (See point C.2.1 in http://www.itu.int/rec/T-REC-X.891-200505-I)
...
    private int decodeNumberOfItemsOfSequence() throws IOException {
        final int b = read();
        if (b < 128) {
            return b + 1;
        } else {
            return (((b & 0x0F) << 16) | (read() << 8) | read()) + 129;
        }
    }
...

-------------------------------------------------
We fixed those using the source code fastinfoset 1.2.7 source code and
managed to progress with parsing of the namespace-names and local-names
correctly and now we are stuck at element-name-surrogates.
It looks like Decoder.decodeIntegerIndexOnSecondBit() implements C.25.2
(from fastinfoset spec.) in the wrong way.

I was wondering if there is anyone that could help us with fixing those
issues or at least confirm that we interpret the specification (
http://www.itu.int/rec/T-REC-X.891-200505-I) in the right way.


Any help much appreciated.
~Andrzej