Skip to content

Commit ace4654

Browse files
committed
Backport #25 fix in 2.4
1 parent 18c411a commit ace4654

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

release-notes/CREDITS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ brharrington@github:
1313
* Reported #17: Boundary error with `float`/`double` values, large content
1414
(2.4.1)
1515

16+
Lee Yun-young (lseeker@github)
17+
* Report #25: Buffer overrun when writing unencoded binary content
18+
(2.4.7 / 2.5.5)
1619

1720
mcmahon356@github:
1821
* Reported 24: Current location does not always updated properly

release-notes/VERSION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-dataformat-smile
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.4.7 (not released)
8+
9+
#25: Buffer overrun when trying to write longer binary content
10+
(report by Lee Y-Y)
11+
712
2.4.6 (23-Apr-2015)
813

914
#24: Current location does not always updated properly

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,9 @@ private final int _writeBytes(InputStream in, int bytesLeft) throws IOException
19041904
_flushBuffer();
19051905
room = _outputEnd - _outputTail;
19061906
}
1907+
if (room > bytesLeft) {
1908+
room = bytesLeft;
1909+
}
19071910
int count = in.read(_outputBuffer, _outputTail, room);
19081911
if (count < 0) {
19091912
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)