Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Cannot parse JSON with integer values bigger than Int.max #56

Open
m-revetria opened this issue Oct 13, 2016 · 1 comment
Open

Cannot parse JSON with integer values bigger than Int.max #56

m-revetria opened this issue Oct 13, 2016 · 1 comment

Comments

@m-revetria
Copy link

I cannot parse a JSON object which has an integer value bigger than Int.max.

The error happens when I call try Jay(parsing: parsing).jsonFromData(serialized) where serialized is an array of UInt8 and represents a valid JSON object. Jay is failing in line 156 of NumberParser.swift:

//look for other number-allowed chars in this context
//although int-section terminating
if intTerm.contains(reader.curr()) {
    //gracefully end this section
    let intString = try digs.string()
    let int = Int(intString)! // FAILING LINE. intString = "9223372036854776000"    
    return int
}

The error is fatal error: unexpectedly found nil while unwrapping an Optional value. The stack trace looks like:

Current stack trace:
0    libswiftCore.dylib                 0x0000000100f03580 swift_reportError + 132
1    libswiftCore.dylib                 0x0000000100f20850 _swift_stdlib_reportFatalError + 61
2    libswiftCore.dylib                 0x0000000100d1c550 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 355
3    libswiftCore.dylib                 0x0000000100e94600 partial apply for (_fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never).(closure #2) + 109
4    libswiftCore.dylib                 0x0000000100d1c550 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 355
5    libswiftCore.dylib                 0x0000000100e4f970 specialized _fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never + 96
6    Jay                                0x000000010081b170 NumberParser.parseInt<A where ...> (A) throws -> Int + 2140
7    Jay                                0x0000000100819f10 NumberParser.parse<A where ...> (with : A) throws -> JSON + 898
8    Jay                                0x0000000100827030 ValueParser.parse<A where ...> (with : A) throws -> JSON + 1653
9    Jay                                0x000000010081d270 ObjectParser.parse<A where ...> (with : A) throws -> JSON + 2269
10   Jay                                0x0000000100827030 ValueParser.parse<A where ...> (with : A) throws -> JSON + 587
11   Jay                                0x000000010081d270 ObjectParser.parse<A where ...> (with : A) throws -> JSON + 2269
12   Jay                                0x0000000100827030 ValueParser.parse<A where ...> (with : A) throws -> JSON + 587
13   Jay                                0x000000010081d270 ObjectParser.parse<A where ...> (with : A) throws -> JSON + 2269
14   Jay                                0x0000000100827030 ValueParser.parse<A where ...> (with : A) throws -> JSON + 587
15   Jay                                0x000000010081d270 ObjectParser.parse<A where ...> (with : A) throws -> JSON + 2269
16   Jay                                0x0000000100827030 ValueParser.parse<A where ...> (with : A) throws -> JSON + 587
17   Jay                                0x00000001007fdf10 ArrayParser.parse<A where ...> (with : A) throws -> JSON + 766
18   Jay                                0x0000000100827030 ValueParser.parse<A where ...> (with : A) throws -> JSON + 1112
19   Jay                                0x000000010081d270 ObjectParser.parse<A where ...> (with : A) throws -> JSON + 2269
20   Jay                                0x0000000100822be0 RootParser.parse<A where ...> (with : A) throws -> JSON + 362
21   Jay                                0x0000000100820920 Parser.parseJsonFromReader<A where ...> (A) throws -> JSON + 132
22   Jay                                0x0000000100820d80 Parser.parseJsonFromData([UInt8]) throws -> JSON + 118
23   Jay                                0x0000000100811950 Jay.jsonFromData([UInt8]) throws -> JSON + 95

I'm using Jay version 1.0.0.

@endocrimes
Copy link
Owner

@m-revetria Good spot, thanks! - Off the top of my head I'm not sure of an ideal way to handle this, but we definitely shouldn't crash on that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants