Skip to content

Shared keys can cause unescaped write of BYTE_MARKER_END_OF_CONTENT #18

Closed
@bleskes

Description

@bleskes

If you write >256 shared keys, the output stream contains -1 byte even though it's not the end of the document. This is a problem for us as we rely on the -1 marker to separate docs from a binary stream without the need to parse them.

Here is a failing junit reproduction:

    @Test
    public void testJacksonEndOfDocByte() throws Exception {
        final String[] currentField = new String[1];
        OutputStream outputStream = new OutputStream() {
            @Override
            public void write(int b) throws IOException {
                if ((byte) b == -1) {
                    fail("got end of doc marker while writing " + currentField[0]);
                }
            }
        };

        SmileGenerator generator =  new SmileFactory().createGenerator(outputStream);
        generator.writeStartObject();
        generator.writeFieldName("a");
        generator.writeStartObject();
        for (int i=0; i < 300; i++) {
            currentField[0] = "f_"+i;
            generator.writeNumberField(currentField[0], i);
            generator.flush();
        }
        currentField[0] = "";
        generator.writeEndObject();
        generator.writeFieldName("b");
        generator.writeStartObject();
        for (int i=0; i < 300; i++) {
            currentField[0] = "f_"+i;
            generator.writeNumberField(currentField[0], i);
            generator.flush();
        }
        currentField[0] = "";
        generator.writeEndObject();
        generator.writeEndObject();
    }

I believe the problem lies in this line, which writes an un escaped byte as the second parameter:

_writeBytes(((byte) (TOKEN_PREFIX_KEY_SHARED_LONG + (ix >> 8))), (byte) ix);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions