Skip to content

Commit f54218b

Browse files
committed
Backport #25 fix, prepare for 2.3.5.1 for smile module
1 parent 0f48593 commit f54218b

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<groupId>com.fasterxml.jackson.dataformat</groupId>
1212
<artifactId>jackson-dataformat-smile</artifactId>
13-
<version>2.3.6-SNAPSHOT</version>
13+
<version>2.3.5.1-SNAPSHOT</version>
1414
<name>Jackson-dataformat-Smile</name>
1515
<packaging>bundle</packaging>
1616
<description>Support for reading and writing Smile ("binary JSON")

release-notes/VERSION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ Project: jackson-dataformat-smile
44
=== History: ===
55
------------------------------------------------------------------------
66

7-
2.3.6 (not yet released)
7+
2.3.5.1 (15-Jul-2015)
88

99
#24: Current location does not always updated properly
10+
#25: Buffer overwrite with longer unencoded binary content
1011

1112
2.3.5 (14-Jan-2015)
1213

src/main/java/com/fasterxml/jackson/dataformat/smile/SmileGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,9 @@ private final int _writeBytes(InputStream in, int bytesLeft) throws IOException
18491849
_flushBuffer();
18501850
room = _outputEnd - _outputTail;
18511851
}
1852+
if (room > bytesLeft) {
1853+
room = bytesLeft;
1854+
}
18521855
int count = in.read(_outputBuffer, _outputTail, room);
18531856
if (count < 0) {
18541857
break;

src/test/java/com/fasterxml/jackson/dataformat/smile/TestSmileGeneratorBinary.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.junit.Assert;
66

77
import com.fasterxml.jackson.core.*;
8+
import com.fasterxml.jackson.dataformat.smile.SmileGenerator.Feature;
89

910
public class TestSmileGeneratorBinary extends SmileTestBase
1011
{
@@ -60,6 +61,37 @@ public void testBinaryWithoutLength() throws Exception
6061
jg.close();
6162
}
6263

64+
public void testStreamingBinaryPartly() throws Exception {
65+
_testStreamingBinaryPartly(true);
66+
_testStreamingBinaryPartly(false);
67+
}
68+
69+
private void _testStreamingBinaryPartly(boolean rawBinary) throws Exception
70+
{
71+
final SmileFactory f = new SmileFactory();
72+
f.configure(Feature.ENCODE_BINARY_AS_7BIT, rawBinary);
73+
74+
final byte[] INPUT = TEXT4.getBytes("UTF-8");
75+
ByteArrayInputStream in = new ByteArrayInputStream(INPUT);
76+
77+
ByteArrayOutputStream out = new ByteArrayOutputStream();
78+
JsonGenerator jg = f.createGenerator(out);
79+
jg.writeStartArray();
80+
jg.writeBinary(in, 1);
81+
jg.writeEndArray();
82+
jg.close();
83+
in.close();
84+
85+
JsonParser jp = f.createParser(out.toByteArray());
86+
assertToken(JsonToken.START_ARRAY, jp.nextToken());
87+
assertToken(JsonToken.VALUE_EMBEDDED_OBJECT, jp.nextToken());
88+
byte[] b = jp.getBinaryValue();
89+
assertToken(JsonToken.END_ARRAY, jp.nextToken());
90+
jp.close();
91+
92+
assertEquals(1, b.length);
93+
}
94+
6395
/*
6496
/**********************************************************
6597
/* Helper methods

0 commit comments

Comments
 (0)