-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
961b128
commit de072d3
Showing
6 changed files
with
194 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/BrokenLongBinary186Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.fasterxml.jackson.dataformat.cbor; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
// Mostly for [dataformats-binary#186]: corrupt encoding indicating humongous payload | ||
public class BrokenLongBinary186Test extends CBORTestBase | ||
{ | ||
private final ObjectMapper MAPPER = cborMapper(); | ||
|
||
/* | ||
/********************************************************************** | ||
/* First regular, read-it-all access, from non-chunked | ||
/********************************************************************** | ||
*/ | ||
|
||
// [dataformats-binary#186] | ||
public void testCorruptVeryLongBinary() throws Exception { | ||
// Let's do about 2 GB to likely trigger failure | ||
_testCorruptLong(1_999_999_999, 95000); | ||
} | ||
|
||
// [dataformats-binary#186] | ||
public void testCorruptQuiteLongBinary() throws Exception { | ||
// Value below limit for chunked handling | ||
_testCorruptLong(CBORParser.LONGEST_NON_CHUNKED_BINARY >> 1, 37); | ||
} | ||
|
||
private void _testCorruptLong(int allegedLength, int actualIncluded) throws Exception | ||
{ | ||
JsonParser p = MAPPER.createParser(_createBrokenDoc(allegedLength, actualIncluded)); | ||
assertEquals(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken()); | ||
try { | ||
p.getBinaryValue(); | ||
fail("Should fail"); | ||
} catch (JsonProcessingException e) { | ||
verifyException(e, "Unexpected end-of-input for Binary value"); | ||
verifyException(e, "expected "+allegedLength+" bytes, only found "+actualIncluded); | ||
} | ||
} | ||
|
||
/* | ||
/********************************************************************** | ||
/* And then "streaming" access | ||
/********************************************************************** | ||
*/ | ||
|
||
// [dataformats-binary#186] | ||
public void testQuiteLongStreaming() throws Exception | ||
{ | ||
// Can try bit shorter here, like 500 megs | ||
final int allegedLength = 500_000_000; | ||
|
||
JsonParser p = MAPPER.createParser(_createBrokenDoc(allegedLength, 72000)); | ||
assertEquals(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken()); | ||
try { | ||
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); | ||
p.readBinaryValue(bytes); | ||
fail("Should fail"); | ||
} catch (JsonProcessingException e) { | ||
verifyException(e, "Unexpected end-of-input for Binary value"); | ||
verifyException(e, "expected "+allegedLength+" bytes, only found 72000"); | ||
} | ||
} | ||
|
||
private byte[] _createBrokenDoc(int allegedLength, int actualIncluded) throws Exception | ||
{ | ||
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); | ||
|
||
if (allegedLength > 0xFFFF) { | ||
bytes.write((byte) (CBORConstants.PREFIX_TYPE_BYTES | CBORConstants.SUFFIX_UINT32_ELEMENTS)); | ||
bytes.write((byte) (allegedLength >> 24)); | ||
bytes.write((byte) (allegedLength >> 16)); | ||
bytes.write((byte) (allegedLength >> 8)); | ||
bytes.write((byte) allegedLength); | ||
} else { // assume shorter | ||
bytes.write((byte) (CBORConstants.PREFIX_TYPE_BYTES | CBORConstants.SUFFIX_UINT16_ELEMENTS)); | ||
bytes.write((byte) (allegedLength >> 8)); | ||
bytes.write((byte) allegedLength); | ||
} | ||
// but only include couple of bytes | ||
for (int i = 0; i < actualIncluded; ++i) { | ||
bytes.write((byte) i); | ||
} | ||
return bytes.toByteArray(); | ||
} | ||
|
||
} |
42 changes: 0 additions & 42 deletions
42
.../src/test/java/com/fasterxml/jackson/dataformat/cbor/failing/BrokenLongBinary186Test.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters