Skip to content

Conversation

rosen-vladimirov
Copy link
Contributor

fix: message-unpack-stream parses messages incorrectly in some cases

The message-unpack-stream parses messages incorrectly in case a message with length less than Header length (4) is received - this leads to indefinite recursion. The problem has been introduced in #24 which was fixing another issue - when the length of the new message is less than the buffer header and there's something in the _unfinishedMessage.
To resolve the issue, get the previous logic and improve the check - in case we have partial message from the previous time, just add the current message to it and get in the recursion. In case we do not have previous message and current data is less than 4 bytes, just put it in the _unfinishedMessage and wait for new data.

feat: add tests for message-unpack-stream

Add tests for message-unpack-stream.
Add mocha, chai and istanbul as devDependencies and ensure tests are run before packing the package. Ignore test specific files from the npm package and coverage files from git.

feat: export MessageUnpackStream class

Export MessageUnpackStream class from the index.js, so once the package is required, you can create instances of both IOSDeviceLib and MessageUnpackStream. Move the implementation of IOSDeviceLib to a separate file to simplify the entry point.

The `message-unpack-stream` parses messages incorrectly in case a message with length less than Header length (4) is received - this leads to indefinite recursion. The problem has been introduced in #24 which was fixing another issue - when the length of the new message is less than the buffer header and there's something in the `_unfinishedMessage`.
To resolve the issue, get the previous logic and improve the check - in case we have partial message from the previous time, just add the current message to it and get in the recursion. In case we do not have previous message and current data is less than 4 bytes, just put it in the `_unfinishedMessage` and wait for new data.
Add tests for message-unpack-stream.
Add mocha, chai and istanbul as devDependencies and ensure tests are run before packing the package. Ignore test specific files from the npm package and coverage files from git.
Export MessageUnpackStream class from the index.js, so once the package is required, you can create instances of both IOSDeviceLib and MessageUnpackStream. Move the implementation of IOSDeviceLib to a separate file to simplify the entry point.
@rosen-vladimirov rosen-vladimirov merged commit 3de7c83 into master Jan 15, 2019
@rosen-vladimirov rosen-vladimirov deleted the vladimirov/fix-debug-ios branch January 15, 2019 11:37
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

Successfully merging this pull request may close these issues.

2 participants