Skip to content

cannot read big smile payloads with 2.4.0 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brharrington opened this issue Jun 10, 2014 · 4 comments
Closed

cannot read big smile payloads with 2.4.0 #17

brharrington opened this issue Jun 10, 2014 · 4 comments
Milestone

Comments

@brharrington
Copy link

This is the smallest example I could get to reproduce the issue:

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
import java.io.ByteArrayInputStream;
import java.io.InputStream;

class Test {
  public static void main(String[] args) throws Exception {
    double[] data = new double[4096];
    for (int i = 0; i < data.length; ++i) {
      data[i] = (double) i;
    }

    ObjectMapper mapper = new ObjectMapper(new SmileFactory());
    byte[] encoded = mapper.writeValueAsBytes(data);

    double[] decoded1 = mapper.readValue(encoded, double[].class);
    System.out.println(decoded1.length);

    InputStream input = new ByteArrayInputStream(encoded);
    double[] decoded2 = mapper.readValue(input, double[].class); // This fails on 2.4.0
    System.out.println(decoded2.length);
  }
}

Output with 2.2.0, 2.4.0-rc3, and 2.4.0. Note I only see the issue on 2.4.0 the rc3 version works fine.

$ ./test.sh 2.2.0
4096
4096
$ ./test.sh 2.4.0-rc3
4096
4096
$ ./test.sh 2.4.0
4096
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8000
    at com.fasterxml.jackson.dataformat.smile.SmileParser._fourBytesToIntSlow(SmileParser.java:2063)
    at com.fasterxml.jackson.dataformat.smile.SmileParser._fourBytesToInt(SmileParser.java:2051)
    at com.fasterxml.jackson.dataformat.smile.SmileParser._finishDouble(SmileParser.java:2101)
    at com.fasterxml.jackson.dataformat.smile.SmileParser._finishNumberToken(SmileParser.java:1902)
    at com.fasterxml.jackson.dataformat.smile.SmileParser._parseNumericValue(SmileParser.java:1837)
    at com.fasterxml.jackson.core.base.ParserBase.getDoubleValue(ParserBase.java:662)
    at com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseDoublePrimitive(StdDeserializer.java:669)
    at com.fasterxml.jackson.databind.deser.std.PrimitiveArrayDeserializers$DoubleDeser.deserialize(PrimitiveArrayDeserializers.java:488)
    at com.fasterxml.jackson.databind.deser.std.PrimitiveArrayDeserializers$DoubleDeser.deserialize(PrimitiveArrayDeserializers.java:468)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3051)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2192)
    at Test.main(Test.java:21)
@cowtowncoder
Copy link
Member

Thank you for reporting this. It is obviously unfortunate, doubly so as I had added a big data test before release. But teasing out buffer boundary fails is tricky.
I will fix this for 2.4.1: there is another important fix for jackson-databind for 2.4.0 so probably need to get 2.4.1 out relatively soon.

@cowtowncoder cowtowncoder added this to the 2,4 milestone Jun 11, 2014
@cowtowncoder cowtowncoder modified the milestones: 2.4.1, 2,4 Jun 11, 2014
@cowtowncoder
Copy link
Member

Yes, one boundary check (first of 4 needed) was missing; added. And the reason big data tests didn't catch problem was that I hadn't realized that tests MUST ensure that InputStream is used -- otherwise plain byte[] has no boundaries to cause issues. Should have realized that earlier, but better late than never.

Thank you for reporting this and apologies for nasty regression. 2.4.1 will have this fix, hoping to cut it sometime within next 7 days.

@brharrington
Copy link
Author

Thanks for the quick turn around. I verified that my application works fine with the latest code.

@cowtowncoder
Copy link
Member

Great!

cowtowncoder added a commit that referenced this issue Aug 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants