-
Notifications
You must be signed in to change notification settings - Fork 31.3k
zlib: fix pointer alignment #57727
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
zlib: fix pointer alignment #57727
Conversation
The function AllocForBrotli prefixes the allocated memory with its size, and returns a pointer to the region after it. This pointer can however no longer be suitably aligned. Correct this by allocating the maximum of the the size of the size_t and the max alignment. On Arm 32bits the size_t is 4 bytes long, but the alignment is 8 for some NEON instructions. When Brotli is compiled with optimizations enabled newer GCC versions will use the NEON instructions and trigger a bus error killing node. see google/brotli#1159
/cc @nodejs/cpp-reviewers I can't review this, but I'm very interested as it might fix crashes that we have with the latest V8 update: https://ci.nodejs.org/job/node-test-commit-arm/57862/ |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #57727 +/- ##
==========================================
+ Coverage 90.22% 90.24% +0.01%
==========================================
Files 630 630
Lines 185073 185075 +2
Branches 36222 36222
==========================================
+ Hits 166990 167017 +27
+ Misses 11044 11034 -10
+ Partials 7039 7024 -15
🚀 New features to boost your workflow:
|
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.
I believe that alignof(std::max_align_t)should always be as large as
sizeof(size_t)` so the code might be unnecessarily complicated, but it has the benefit of being clear, so I recommend merging as-is.
Actually I initially wrote that, only using alignof(std::max_align_t), but that might be confusing to read, since it is casted to a <size_t*> thereafter and a reader might be led to believe it is wrong and put a size_t back. In practice the alignment is often, if not always, twice the sizeof(size_t) and guaranteed by the standard not to be less if I am not mistaken. But like this, the code clearly states it intend, make room for a size_t, while keeping the data after it suitable aligned. So it is clearer like this if you ask me and the compiler will remove the Max for us. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Landed in dc035bb |
The function AllocForBrotli prefixes the allocated memory with its size, and returns a pointer to the region after it. This pointer can however no longer be suitably aligned. Correct this by allocating the maximum of the the size of the size_t and the max alignment. On Arm 32bits the size_t is 4 bytes long, but the alignment is 8 for some NEON instructions. When Brotli is compiled with optimizations enabled newer GCC versions will use the NEON instructions and trigger a bus error killing node. see google/brotli#1159 PR-URL: nodejs#57727 Reviewed-By: Shelley Vohr <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
@targos are there any plans to backport this to LTS versions? |
The function AllocForBrotli prefixes the allocated memory with its size, and returns a pointer to the region after it. This pointer can however no longer be suitably aligned. Correct this by allocating the maximum of the the size of the size_t and the max alignment.
On Arm 32bits the size_t is 4 bytes long, but the alignment is 8 for some NEON instructions. When Brotli is compiled with optimizations enabled newer GCC versions will use the NEON instructions and trigger a bus error killing node.
see google/brotli#1159
I don't think there is any additional test needed, since existing test will crash node already.
Not sure about the notable-change label.