Search in sources :

Example 11 with CBORParser

use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jackson-dataformats-binary by FasterXML.

the class ParseIncompleteArray240Test method testIncompleteFixedSizeObject.

// And might as well do the same for Objects too
public void testIncompleteFixedSizeObject() throws Exception {
    final byte[] input = { (byte) 0xA3 };
    try (CBORParser p = cborParser(F, input)) {
        assertToken(JsonToken.START_OBJECT, p.nextToken());
        try {
            p.nextToken();
            fail("Should NOT pass");
        } catch (StreamReadException e) {
            verifyException(e, "Unexpected end-of-input in Object value: expected 3 more");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 12 with CBORParser

use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jackson-dataformats-binary by FasterXML.

the class ParseInvalidUTF8String236Test method testShortString236TruncatedString.

// Variant where the length itself exceeds buffer
public void testShortString236TruncatedString() throws Exception {
    // String with length of 6 bytes claimed; only 5 provided
    final byte[] input = { 0x63, 0x41, 0x2d };
    try (CBORParser p = cborParser(input)) {
        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        try {
            String str = p.getText();
            fail("Should have failed, did not, String = '" + str + "'");
        } catch (StreamReadException e) {
            verifyException(e, "Unexpected end-of-input in VALUE_STRING");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 13 with CBORParser

use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jackson-dataformats-binary by FasterXML.

the class ParseInvalidUTF8String236Test method testShortString236EndsWithPartialUTF8.

// Variant where the length would be valid, but the last byte is partial UTF-8
// code point
public void testShortString236EndsWithPartialUTF8() throws Exception {
    final byte[] input = { 0x63, 0x41, 0x2d, (byte) 0xda };
    try (CBORParser p = cborParser(input)) {
        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        try {
            String str = p.getText();
            fail("Should have failed, did not, String = '" + str + "'");
        } catch (StreamReadException e) {
            verifyException(e, "Malformed UTF-8 character at the end of");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 14 with CBORParser

use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jackson-dataformats-binary by FasterXML.

the class ParseInvalidUTF8String236Test method testShortString237InvalidTextValue.

public void testShortString237InvalidTextValue() throws Exception {
    // String with length of 2 bytes, but a few null bytes as fillers to
    // avoid buffer boundary
    // (2nd byte implies 2-byte sequence but 3rd byte does not have high-bit set)
    byte[] input2 = { 0x62, (byte) 0xCF, 0x2d, 0, 0, 0, 0, 0, 0 };
    try (CBORParser p = cborParser(input2)) {
        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        try {
            String str = p.getText();
            fail("Should have failed, did not, String = '" + str + "'");
        } catch (StreamReadException e) {
            verifyException(e, "Invalid UTF-8 middle byte 0x2d");
        }
    }
    // but let's also validate 3-byte variant as well
    byte[] input3 = { 0x63, (byte) 0xEF, (byte) 0x8e, 0x2d, 0, 0, 0, 0, 0, 0 };
    try (CBORParser p = cborParser(input3)) {
        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        try {
            String str = p.getText();
            fail("Should have failed, did not, String = '" + str + "'");
        } catch (StreamReadException e) {
            verifyException(e, "Invalid UTF-8 middle byte 0x2d");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 15 with CBORParser

use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jackson-dataformats-binary by FasterXML.

the class ParseInvalidUTF8String236Test method testShortString237InvalidName.

public void testShortString237InvalidName() throws Exception {
    // Object with 2-byte invalid name
    byte[] input2 = { // Object, indefinite length
    (byte) 0xBF, // 2-byte name but invalid second byte
    0x62, // 2-byte name but invalid second byte
    (byte) 0xCF, // 2-byte name but invalid second byte
    0x2e, // int value of 33
    0x21, // Object END marker
    (byte) 0xFF, // padding
    0, // padding
    0, // padding
    0, // padding
    0 };
    try (CBORParser p = cborParser(input2)) {
        assertToken(JsonToken.START_OBJECT, p.nextToken());
        try {
            p.nextToken();
            String str = p.getText();
            fail("Should have failed, did not, String = '" + str + "'");
        } catch (StreamReadException e) {
            verifyException(e, "Invalid UTF-8 middle byte 0x2e");
        }
    }
    // but let's also validate 3-byte variant as well
    byte[] input3 = { // Object, indefinite length
    (byte) 0xBF, // 3-byte name but invalid third byte
    0x62, // 3-byte name but invalid third byte
    (byte) 0xEF, // 3-byte name but invalid third byte
    (byte) 0x8e, // 3-byte name but invalid third byte
    0x2f, // int value of 34
    0x22, // Object END marker
    (byte) 0xFF, // padding
    0, // padding
    0, // padding
    0, // padding
    0 };
    try (CBORParser p = cborParser(input3)) {
        assertToken(JsonToken.START_OBJECT, p.nextToken());
        try {
            p.nextToken();
            String str = p.getText();
            fail("Should have failed, did not, String = '" + str + "'");
        } catch (StreamReadException e) {
            verifyException(e, "Truncated UTF-8 character in Map key (2 bytes)");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Aggregations

CBORParser (com.fasterxml.jackson.dataformat.cbor.CBORParser)22 StreamReadException (com.fasterxml.jackson.core.exc.StreamReadException)9 CBORGenerator (com.fasterxml.jackson.dataformat.cbor.CBORGenerator)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 JsonLocation (com.fasterxml.jackson.core.JsonLocation)1 JsonToken (com.fasterxml.jackson.core.JsonToken)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 PublicKey (com.quorum.tessera.encryption.PublicKey)1 Fido2RuntimeException (io.jans.fido2.exception.Fido2RuntimeException)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1