Skip to content

Commit

Permalink
Fix #240
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 30, 2021
1 parent db7bffa commit 0659e8c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,9 @@ public JsonToken nextToken() throws IOException
// also: clear any data retained so far
_binaryValue = null;

/* First: need to keep track of lengths of defined-length Arrays and
* Objects (to materialize END_ARRAY/END_OBJECT as necessary);
* as well as handle names for Object entries.
*/
// First: need to keep track of lengths of defined-length Arrays and
// Objects (to materialize END_ARRAY/END_OBJECT as necessary);
// as well as handle names for Object entries.
if (_parsingContext.inObject()) {
if (_currToken != JsonToken.FIELD_NAME) {
_tagValue = -1;
Expand Down Expand Up @@ -3422,32 +3421,34 @@ protected void _closeInput() throws IOException {

@Override
protected void _handleEOF() throws JsonParseException {
if (!_parsingContext.inRoot()) {
String marker = _parsingContext.inArray() ? "Array" : "Object";
_reportInvalidEOF(String.format(
": expected close marker for %s (start marker at %s)",
marker,
_parsingContext.getStartLocation(_ioContext.getSourceReference())),
null);
if (_parsingContext.inRoot()) {
return;
}
String marker = _parsingContext.inArray() ? "Array" : "Object";
_reportInvalidEOF(String.format(
": expected close marker for %s (start marker at %s)",
marker,
_parsingContext.getStartLocation(_ioContext.getSourceReference())),
null);
}

/*
/**********************************************************
/* Internal methods, error handling, reporting
/**********************************************************
*/

protected JsonToken _handleCBOREOF() throws IOException {
/* NOTE: here we can and should close input, release buffers,
* since this is "hard" EOF, not a boundary imposed by
* header token.
*/
// NOTE: here we can and should close input, release buffers, since
// this is "hard" EOF, not a boundary imposed by header token.
_tagValue = -1;
close();
// 30-Jan-2021, tatu: But also MUST verify that end-of-content is actually
// allowed (see [dataformats-binary#240] for example)
_handleEOF();
return (_currToken = null);
}

/*
/**********************************************************
/* Internal methods, error handling, reporting
/**********************************************************
*/

protected void _invalidToken(int ch) throws JsonParseException {
ch &= 0xFF;
if (ch == 0xFF) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.fasterxml.jackson.dataformat.cbor.parse;

import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import com.fasterxml.jackson.dataformat.cbor.CBORParser;
import com.fasterxml.jackson.dataformat.cbor.CBORTestBase;

public class ParseInvalidArray240Test extends CBORTestBase
{
private final CBORFactory F = cborFactory();

// [dataformats-binary#240]
public void test1ByteIncompleteArray() throws Exception
{
final byte[] input = { (byte) 0x84 };
try (CBORParser p = cborParser(F, input)) {
assertToken(JsonToken.START_ARRAY, p.nextToken());
try {
p.nextToken();
fail("Should NOT pass");
} catch (StreamReadException e) {
verifyException(e, "Unexpected end-of-input: expected close marker for Array");
}
}
}
}

0 comments on commit 0659e8c

Please sign in to comment.