-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix HalModuleParser.parsePrefix() when parsing valid compressed binaries #41
Fix HalModuleParser.parsePrefix() when parsing valid compressed binaries #41
Conversation
…s unknown platform, flags and function
… causes HalModuleParser.parsePrefix() to parse the module prefix at incorrect location
83f985b
to
37764d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the code looks good, reads a lot better and I appreciate the code clean up you've done.
I'm a bit 🤔 about the strict
option to _validateModulePrefix
and would like to discuss before approval.
0x184, // Gen 2 | ||
0xC0, // Bluez | ||
0x10C, // Core | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this reads far better I really like this cleanup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I was going to suggest adding a zero offset to the list of preferred ones, but then I noticed that it's actually there, it just didn't deserve its own line in the array definition. I'd add a comment that the module header typically starts at 0 offset if it's a user part or other non-system/bootloader module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved 0 to a separate line and added an additional comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What an awesome PR 👍
const expectedSize = endAddr - startAddr + 4 /* CRC-32 */; | ||
if (fileBuffer.length < expectedSize) { | ||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment why we don't want to fail immediately if the file is larger than what is specified in the module header would be helpful here (padded/combined modules).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const allFlags = Object.values(ModuleInfo.Flags).reduce((a, b) => (a | b), 0); | ||
if ((prefixInfo.moduleFlags & (~allFlags)) === 0) { | ||
result.score++; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-zero version numbers (of the module itself and its dependencies) can be another 0.25 score points 🙂 Also, the fact that start/end addresses are in the internal flash (where applicable) that was checked in the old code was a good indication that we're dealing with a valid module, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the fact that start/end addresses are in the internal flash (where applicable) that was checked in the old code was a good indication that we're dealing with a valid module, IMO.
I think we should be able to get away without these kinds of platform-specific checks and probably should if we can. It's also impossible to implement such checks properly for Gen 3 platforms as addresses in the internal flash are generic 0 to 1MB.
Non-zero version numbers (of the module itself and its dependencies) can be another 0.25 score points 🙂
As discussed in Slack, let's keep things as-is. Given all the other checks it's anyway highly likely that the versions will not be zero.
(userModuleStartAddy.indexOf("20") == 0); // stack is located in ram at 0x2000000 | ||
|
||
if (isCore) { | ||
return 0x10C; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes. Thank you so much for doing this.
0x184, // Gen 2 | ||
0xC0, // Bluez | ||
0x10C, // Core | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I was going to suggest adding a zero offset to the list of preferred ones, but then I noticed that it's actually there, it just didn't deserve its own line in the array definition. I'd add a comment that the module header typically starts at 0 offset if it's a user part or other non-system/bootloader module.
lib/HalModuleParser.js
Outdated
@@ -23,9 +23,9 @@ var when = require('when'); | |||
var pipeline = require('when/pipeline'); | |||
var utilities = require('./utilities.js'); | |||
var buffers = require('h5.buffers'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module is no longer used in this file. I'd also check if we even need this dependency at all, given the changes in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, no longer required. Removed the dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates, looks great
Current version of binary-version-reader may provide invalid module prefix for valid compressed modules due to hardware platform-specific heuristics.
This causes errors in Device Service and disables compression and module combination when performing OTAs:
The following binary after compression will not be correctly parsed:
tracker-system-part1@3.1.0-alpha.2.bin
Compressed:
compressed_tracker-system-part1@3.1.0-alpha.2.bin
This should instead be: