-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
f1f9343
commit ab74693
Showing
4 changed files
with
103 additions
and
20 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
49 changes: 43 additions & 6 deletions
49
...est/java/com/fasterxml/jackson/dataformat/cbor/failing/ParseInvalidUTF8String236Test.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 |
---|---|---|
@@ -1,20 +1,57 @@ | ||
package com.fasterxml.jackson.dataformat.cbor.failing; | ||
|
||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.core.*; | ||
import com.fasterxml.jackson.core.exc.StreamReadException; | ||
import com.fasterxml.jackson.dataformat.cbor.CBORParser; | ||
import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; | ||
|
||
public class ParseInvalidUTF8String236Test extends CBORTestBase | ||
{ | ||
// [dataformats-binary#236]: Ends with the first byte of alleged 2-byte | ||
// UTF-8 character; parser trying to access second byte beyond end. | ||
public void testArrayIssue236() throws Exception | ||
// [dataformats-binary#236]: Original version; broken UTF-8 all around. | ||
// but gets hit by end-of-input only (since content not validated) | ||
public void testShortString236Original() throws Exception | ||
{ | ||
final byte[] input = {0x66, (byte) 0xef, 0x7d, 0x7d, 0xa, 0x2d, (byte) 0xda}; | ||
try (CBORParser p = cborParser(input)) { | ||
assertToken(JsonToken.VALUE_STRING, p.nextToken()); | ||
assertEquals("foobar", p.getText()); | ||
assertNull(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 0x7d"); | ||
} | ||
} | ||
} | ||
|
||
// 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"); | ||
} | ||
} | ||
} | ||
|
||
// 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"); | ||
} | ||
} | ||
} | ||
} |
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