Skip to content

Commit 2227244

Browse files
committed
Fix #17, add suggested unit test (and improve other big-data test; must ensure InputStream is used, not byte[])
1 parent d8f6afe commit 2227244

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

release-notes/CREDITS

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ Here are people who have contributed to Smile decoded plug-in development
55
Tatu Saloranta, [email protected]: author
66

77
Steven Schlansker:
8-
98
* Reported [Issue-2]: SmileParser failed to properly decoded surrogate-pair
109
characters for long strings
1110
(2.0.2)
11+
12+
brharrington@github:
13+
* Reported #17: Boundary error with `float`/`double` values, large content
14+
(2.4.1)

release-notes/VERSION

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
Project: jackson-dataformat-smile
2-
Version: 2.4.0 (02-Jun-2014)
2+
Version: 2.4.1 (xx-Jun-2014)
33

4-
#16: Support handling of "Stringified" numbers
4+
#17: Boundary error with `float`/`double` values, large content
5+
(reported by brharrington@github)
56

67
------------------------------------------------------------------------
78
=== History: ===
89
------------------------------------------------------------------------
910

11+
2.4.0 (02-Jun-2014)
12+
13+
#16: Support handling of "Stringified" numbers
14+
1015
2.3.2 (01-Mar-2014)
1116

1217
#15: Problem with SmileGenerator._writeBytes(...), bounds checks

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

+3
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,9 @@ private final int _fourBytesToInt() throws IOException
20552055

20562056
private final int _fourBytesToIntSlow() throws IOException
20572057
{
2058+
if (_inputPtr >= _inputEnd) {
2059+
loadMoreGuaranteed();
2060+
}
20582061
int i = _inputBuffer[_inputPtr++]; // first 7 bits
20592062
if (_inputPtr >= _inputEnd) {
20602063
loadMoreGuaranteed();

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

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.dataformat.smile;
22

3+
import java.io.*;
34
import java.util.*;
45

56
import com.fasterxml.jackson.databind.*;
@@ -121,7 +122,8 @@ public void testRoundTrip() throws Exception
121122
ObjectMapper mapper = smileMapper(false);
122123

123124
byte[] smile1 = mapper.writeValueAsBytes(citm);
124-
Citm citm2 = mapper.readValue(smile1, Citm.class);
125+
// IMPORTANT: use InputStream so boundary conditions are actually checked
126+
Citm citm2 = mapper.readValue(new ByteArrayInputStream(smile1), Citm.class);
125127
byte[] smile2 = mapper.writeValueAsBytes(citm2);
126128

127129
assertEquals(smile1.length, smile2.length);
@@ -138,4 +140,34 @@ public void testRoundTrip() throws Exception
138140
assertEquals(citm.topicSubTopics.size(), citm2.topicSubTopics.size());
139141
assertEquals(citm.venueNames.size(), citm2.venueNames.size());
140142
}
143+
144+
public void testIssue17BoundaryWithFloat() throws Exception
145+
{
146+
_testWithFloats(false);
147+
_testWithFloats(true);
148+
}
149+
150+
private void _testWithFloats(boolean useHeader) throws Exception
151+
{
152+
double[] data = new double[4096];
153+
for (int i = 0; i < data.length; ++i) {
154+
data[i] = (double) i;
155+
}
156+
ObjectMapper mapper = smileMapper(useHeader);
157+
byte[] encoded = mapper.writeValueAsBytes(data);
158+
159+
// first, read from byte array; no boundary
160+
double[] decoded = mapper.readValue(encoded, double[].class);
161+
assertEquals(data.length, decoded.length);
162+
163+
// and then via InputStream
164+
decoded = mapper.readValue(new ByteArrayInputStream(encoded), double[].class); // This fails on 2.4.0
165+
assertEquals(data.length, decoded.length);
166+
167+
for (int i = 0; i < data.length; ++i) {
168+
if (data[i] != decoded[i]) {
169+
assertEquals("Different value at #"+i, data[i], decoded[i]);
170+
}
171+
}
172+
}
141173
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected ObjectMapper smileMapper() {
8484
}
8585

8686
protected ObjectMapper smileMapper(boolean requireHeader) {
87-
return smileMapper(requireHeader, false, false);
87+
return smileMapper(requireHeader, requireHeader, false);
8888
}
8989

9090
protected ObjectMapper smileMapper(boolean requireHeader,

0 commit comments

Comments
 (0)