|
| 1 | +package com.fasterxml.jackson.dataformat.cbor.failing; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.core.JsonParser; |
| 4 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 5 | +import com.fasterxml.jackson.core.JsonToken; |
| 6 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 7 | +import com.fasterxml.jackson.dataformat.cbor.CBORConstants; |
| 8 | +import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; |
| 9 | + |
| 10 | +// Mostly for [dataformats-binary#186]: corrupt encoding indicating humongous payload |
| 11 | +public class BrokenLongBinary186Test extends CBORTestBase |
| 12 | +{ |
| 13 | + private final ObjectMapper MAPPER = cborMapper(); |
| 14 | + |
| 15 | + // [dataformats-binary#186] |
| 16 | + public void testCorruptVeryLongBinary() throws Exception |
| 17 | + { |
| 18 | + // Let's do 999,999,999 bytes to likely trigger failure |
| 19 | + final int LONG_LEN = 999_999_999; |
| 20 | + byte[] DOC = new byte[] { |
| 21 | + (byte) (CBORConstants.PREFIX_TYPE_BYTES | CBORConstants.SUFFIX_UINT32_ELEMENTS), |
| 22 | + (byte) (LONG_LEN >> 24), |
| 23 | + (byte) (LONG_LEN >> 16), |
| 24 | + (byte) (LONG_LEN >> 8), |
| 25 | + (byte) LONG_LEN, |
| 26 | + // but only include 2 bytes |
| 27 | + 0, 0 |
| 28 | + }; |
| 29 | + JsonParser p = MAPPER.createParser(DOC); |
| 30 | + assertEquals(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken()); |
| 31 | + try { |
| 32 | + p.getBinaryValue(); |
| 33 | + fail("Should fail"); |
| 34 | + } catch (JsonProcessingException e) { |
| 35 | +// e.printStackTrace(); |
| 36 | + |
| 37 | + // 01-Dec-2020, tatu: Need to decide what kind of exception should be |
| 38 | + // produced... |
| 39 | + verifyException(e, "foobar"); |
| 40 | + } |
| 41 | + } |
| 42 | +} |
0 commit comments