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

Bug: UInt64 maybe negativ #72

Closed
szuniverse opened this issue Apr 21, 2015 · 19 comments
Closed

Bug: UInt64 maybe negativ #72

szuniverse opened this issue Apr 21, 2015 · 19 comments

Comments

@szuniverse
Copy link

Hi.

Very often get a runtime error on the latest version.

This is around the 500. row:
var len = dataLength
if dataLength > UInt64(bufferLen) {
len = UInt64(bufferLen-offset) // runtime error position
}

the bufferLen value is 8, and the offset value is 10. I dont know how it happens but it will be negativ..
Unfortunately I didnt implement the server so I cannot check it. maybe it would be a good way to handle this case in this library.

@daltoniam
Copy link
Owner

Yeah a UInt64 should never be negative as it is unsigned. I'm not sure how the bufferLen could be 8 and the offset be 10. That would equal -2 which certainly would crash an unsigned number. The code you are referencing means the webSocket frame (packet) doesn't have a full UInt64 value to read the length of the data. Can you verify what the size of dataLength? There isn't an easy way to handle this in the library as a webSocket packet should always all of it's framing information.

@daltoniam
Copy link
Owner

@szuniverse where you able to verify with the size of dataLength was or track down any more information?

@szuniverse
Copy link
Author

Unfortunately in the last few weeks I couldn't working on my project. So I will write more details If I will have enough time

@daltoniam
Copy link
Owner

OK sounds good. I will go ahead and close this issue out until then. Just reopen it when you are ready.

@wispur
Copy link

wispur commented May 22, 2015

@daltoniam
Hello~
We are facing the same issue, in our case the dataLength is 126, which means we should have 2 more byte following to read, however the bufferLen is only 3 (offset being 4).
We suspect we would need to create a temporary WSResponse in order to postpone the processing just like if we lack normal data even though this is a rare case.

@daltoniam
Copy link
Owner

@wispur thanks for the report. If you get any details on a consistent way to reproduce this, let me know and I will look into it.

@wispur
Copy link

wispur commented May 26, 2015

@daltoniam Thanks for the reply too! I am also trying to reproduce this issue reliably, so far this issue just pops randomly when I do not expect it to happen :(

@daltoniam daltoniam mentioned this issue Jun 1, 2015
@szuniverse
Copy link
Author

Hi. Last past days I tried to reproduce this bug on a consistent way but I cant.. Its seems randomly, but its a real bug, which is always crashes the app
I think the Starscream can handle this case somehow and receive an error message or something like this would be better than the crash.
I think its time to reopen this bug, and handle this bug with an error message, and dont crash the app when this weird situation occurs

[ And one more thing... In this weekend my router has been broken, and I have to use an older router more than 7years old. And this bug appears more frequently, so I think it depends on the router. But I am not sure, this is my experience.. ]

@daltoniam
Copy link
Owner

If I knew what was causing the crash, I would just fix it 😄. It isn't something that can just be handled and not crash, we have to track down a cause and hopefully a fix. My working theory is that a huge packet is coming through, but is fragmented just right, so we can't read the expect length of the packet. I am going to try adding that protection logic and see if it resolves the issue. I will try to do that in the next few days, but no promises as it has been a busy last few weeks.

@daltoniam
Copy link
Owner

@szuniverse try adding this at line 499 (right below the dataLength checkers):

if bufferLen < offset {
    fragBuffer = NSData(bytes: buffer, length: bufferLen)
    return
}

Also here is a screenshot for reference:
screen shot 2015-07-06 at 10 34 06 am

@szuniverse
Copy link
Author

Okey. thanks a lot! I will "test" it, I hope the crash will dissapear without side effect :)
Will you add these lines to the official version later, if you will have enough time?

@daltoniam
Copy link
Owner

Yes I will, hoping it works 😄 . Let me know if it fixes and I will add it into the official release.

@szuniverse
Copy link
Author

Well, It works fine. The runtime crash has been resolved, but give me one week to test it. I will write you soon.

@daltoniam
Copy link
Owner

Great to hear. If all goes well, we can run it threw the autobahn tests again and cut a new version!

@szuniverse
Copy link
Author

Okey. I tested it on this weekend and everything works fine. The crash has been resolved :)
I think its time to make autobahn tests again and cut a new version!

@daltoniam
Copy link
Owner

Awesome! I will try and run the test some time this week and cut the new version.

@szuniverse
Copy link
Author

Hi! Do you merged this bug fix to the master?

@daltoniam
Copy link
Owner

I did, master should have all the fixes. Haven't create the new tag yet, was finishing the final touches on an autobahn test/example before creating the 0.9.4 tag.

@szuniverse
Copy link
Author

Awesome! :)

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

3 participants