Skip to content
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

Problem with big integers #1

Open
joaopedro1520 opened this issue Jul 25, 2018 · 4 comments
Open

Problem with big integers #1

joaopedro1520 opened this issue Jul 25, 2018 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@joaopedro1520
Copy link

Hello, I'm implementing encode/decode and noticed a problem with both of them when using big numbers. I'm using the following set of data.

let barr = [**1531842146400**,[1332, 0, "0.3.0-dev", "0.3.0-dev", "4.0.2", "866191031649643", "8935101811542082547", "M95FAR02A08","AXN_2.32_3337_15010801", 3, 0],[1398, 8, NSSimpleValue(nil), NSSimpleValue(nil), NSSimpleValue(nil), NSSimpleValue(nil), NSSimpleValue(nil)],[1376, 7, 1]] as [Any]

 let cc = CBOR.encode(barr as NSArray)

which encoded using the playground results in 9f1b00000164a8e830608b1905340069302e332e302d64657669302e332e302d64657665342e302e326f38363631393130333136343936343373383933353130313831313534323038323534376b4d393546415230324130387641584e5f322e33325f333333375f313530313038303103008719057608f6f6f6f6f6831905600701ff

My problem is that the first value 1531842146400 since it's a bit integer can't be encoded (crashes) and when decoding it returns an empty array not showing any values. But if I use a smaller number everything works fine. What can I do to work around this situation?

Thanks

@hassan-shahbazi hassan-shahbazi added bug Something isn't working good first issue Good for newcomers labels Jul 26, 2018
@hassan-shahbazi
Copy link
Owner

Hello joaopedro,
Thanks for opening this issue. I will check and work on it soon. Until that, you can fork the repository and try to resolve it by making the "pull requests".

@joaopedro1520
Copy link
Author

Hello, I've tested your new code changes and I'm getting different crashes now. On decoding I still get an empty array due to the big integer since its the first member of the array. On encoding I'm getting a crashes on an optional.

My encoding test case:

        let strinx  = Array<UInt8>(hex:  "9f1b00000164a8e830608b1905340069302e332e302d64657669302e332e302d64657665342e302e326f38363631393130333136343936343373383933353130313831313534323038323534376b4d393546415230324130387641584e5f322e33325f333333375f313530313038303103008719057608f6f6f6f6f6831905600701ff")
        
        let decoded = (try! CBOR.decode(strinx))!
    
        print(decoded)

My decoding test case

        let cv = [NSNumber(value: UInt64(integerLiteral: 1531842146400)),[1332,0 , "0.3.0-dev", "0.3.0-dev","4.0.2","866191031649643", "8935101811542082547","M95FAR02A08","AXN_2.32_3337_15010801",3,0],[1398,8,NSSimpleValue(nil),NSSimpleValue(nil),NSSimpleValue(nil),NSSimpleValue(nil),NSSimpleValue(nil)],[1376,7,1]] as [Any]
        
            print(CBOR.encode(cv as NSArray))

The crash
captura de ecra 2018-07-27 as 09 54 59

Thank you

@hassan-shahbazi
Copy link
Owner

hassan-shahbazi commented Jul 27, 2018

Hello,
I've seen the issues, will work on them. The main problem is that I have not implemented Indefinite-Length Arrays and Maps yet. May take more times to be fixed

@xuaninbox
Copy link

Hey,

Is it possible to create a release with this fix~
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants