fix(codesign): pad LINKEDIT to multiple of page size when reading #66
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When we are creating a new CodeSignature, we align its offset up to a multiple of the page size; we then read the existing LINKEDIT section (and the entire beginning of the file, for signing) based on the location of that code signature. If the existing LINKEDIT section's end was not page-aligned, we get an EOF when attempting to read up to the page-aligned flie size, causing signing to fail.
This change limits our read to the actual size of the file (or LINKEDIT section, at least), while keeping the buffer we read into the correct size (and therefore implicitly padding it with zeroes, which will get written out when we rewrite the LINKEDIT section and new signature).
I had never encountered this bug before because we'd never seen a MachO whose LINKEDIT section didn't end on a page boundary, but the newest Electron release (which includes a compiler change) seems to end 4 bytes short of a page boundary.