electron/patches/node/zlib_fix_pointer_alignment.patch

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
2.3 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jeroen Hofstee <jhofstee@victronenergy.com>
Date: Tue, 1 Apr 2025 20:09:31 +0000
Subject: zlib: fix pointer alignment
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 https://github.com/google/brotli/issues/1159
diff --git a/src/node_zlib.cc b/src/node_zlib.cc
chore: bump node to v22.15.0 (35-x-y) (#46740) * chore: bump node in DEPS to v22.15.0 * inspector: fix GN build https://github.com/nodejs/node/pull/56798 * test: search cctest files https://github.com/nodejs/node/pull/56791 * crypto: fix missing OPENSSL_NO_ENGINE guard https://github.com/nodejs/node/pull/57012 * test,crypto: make tests work for BoringSSL https://github.com/nodejs/node/pull/57021 * module: use synchronous hooks for preparsing in import(cjs) https://github.com/nodejs/node/pull/55698 * deps: update simdjson to 3.12.0 https://github.com/nodejs/node/pull/56874 * build: remove explicit linker call to libm on macOS https://github.com/nodejs/node/pull/56901 * test: make eval snapshot comparison more flexible https://github.com/nodejs/node/pull/57020 * src: allow embedder customization of OOMErrorHandler https://github.com/nodejs/node/pull/57325 * src: do not pass nullptr to std::string ctor https://github.com/nodejs/node/pull/57354 * build: fix GN build failure * build: fix patch indices * crypto: expose security levels https://github.com/nodejs/node/pull/56601 * zlib: add zstd support https://github.com/nodejs/node/pull/52100 * test: move crypto related common utilities in common/crypto https://github.com/nodejs/node/pull/56714 * test: disable test-https-client-renegotiation-limit BoringSSL doesn't support caller-initiated renegotiation - see https://source.chromium.org/chromium/chromium/src/+/main:third_party/boringssl/src/ssl/ssl_lib.cc;l=1627-1631 * chore: fixup indices --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2025-05-13 21:56:52 +09:00
index 0b7c47b326c7c5480086228b3d40d54c260ef16a..7e6b38ecd1aa360012c0d73e94412530a48cb8c3 100644
--- a/src/node_zlib.cc
+++ b/src/node_zlib.cc
chore: bump node to v22.15.0 (35-x-y) (#46740) * chore: bump node in DEPS to v22.15.0 * inspector: fix GN build https://github.com/nodejs/node/pull/56798 * test: search cctest files https://github.com/nodejs/node/pull/56791 * crypto: fix missing OPENSSL_NO_ENGINE guard https://github.com/nodejs/node/pull/57012 * test,crypto: make tests work for BoringSSL https://github.com/nodejs/node/pull/57021 * module: use synchronous hooks for preparsing in import(cjs) https://github.com/nodejs/node/pull/55698 * deps: update simdjson to 3.12.0 https://github.com/nodejs/node/pull/56874 * build: remove explicit linker call to libm on macOS https://github.com/nodejs/node/pull/56901 * test: make eval snapshot comparison more flexible https://github.com/nodejs/node/pull/57020 * src: allow embedder customization of OOMErrorHandler https://github.com/nodejs/node/pull/57325 * src: do not pass nullptr to std::string ctor https://github.com/nodejs/node/pull/57354 * build: fix GN build failure * build: fix patch indices * crypto: expose security levels https://github.com/nodejs/node/pull/56601 * zlib: add zstd support https://github.com/nodejs/node/pull/52100 * test: move crypto related common utilities in common/crypto https://github.com/nodejs/node/pull/56714 * test: disable test-https-client-renegotiation-limit BoringSSL doesn't support caller-initiated renegotiation - see https://source.chromium.org/chromium/chromium/src/+/main:third_party/boringssl/src/ssl/ssl_lib.cc;l=1627-1631 * chore: fixup indices --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2025-05-13 21:56:52 +09:00
@@ -608,7 +608,8 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
}
static void* AllocForBrotli(void* data, size_t size) {
- size += sizeof(size_t);
+ constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t));
+ size += offset;
CompressionStream* ctx = static_cast<CompressionStream*>(data);
char* memory = UncheckedMalloc(size);
if (memory == nullptr) [[unlikely]] {
chore: bump node to v22.15.0 (35-x-y) (#46740) * chore: bump node in DEPS to v22.15.0 * inspector: fix GN build https://github.com/nodejs/node/pull/56798 * test: search cctest files https://github.com/nodejs/node/pull/56791 * crypto: fix missing OPENSSL_NO_ENGINE guard https://github.com/nodejs/node/pull/57012 * test,crypto: make tests work for BoringSSL https://github.com/nodejs/node/pull/57021 * module: use synchronous hooks for preparsing in import(cjs) https://github.com/nodejs/node/pull/55698 * deps: update simdjson to 3.12.0 https://github.com/nodejs/node/pull/56874 * build: remove explicit linker call to libm on macOS https://github.com/nodejs/node/pull/56901 * test: make eval snapshot comparison more flexible https://github.com/nodejs/node/pull/57020 * src: allow embedder customization of OOMErrorHandler https://github.com/nodejs/node/pull/57325 * src: do not pass nullptr to std::string ctor https://github.com/nodejs/node/pull/57354 * build: fix GN build failure * build: fix patch indices * crypto: expose security levels https://github.com/nodejs/node/pull/56601 * zlib: add zstd support https://github.com/nodejs/node/pull/52100 * test: move crypto related common utilities in common/crypto https://github.com/nodejs/node/pull/56714 * test: disable test-https-client-renegotiation-limit BoringSSL doesn't support caller-initiated renegotiation - see https://source.chromium.org/chromium/chromium/src/+/main:third_party/boringssl/src/ssl/ssl_lib.cc;l=1627-1631 * chore: fixup indices --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2025-05-13 21:56:52 +09:00
@@ -617,7 +618,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
*reinterpret_cast<size_t*>(memory) = size;
ctx->unreported_allocations_.fetch_add(size,
std::memory_order_relaxed);
- return memory + sizeof(size_t);
+ return memory + offset;
}
static void FreeForZlib(void* data, void* pointer) {
chore: bump node to v22.15.0 (35-x-y) (#46740) * chore: bump node in DEPS to v22.15.0 * inspector: fix GN build https://github.com/nodejs/node/pull/56798 * test: search cctest files https://github.com/nodejs/node/pull/56791 * crypto: fix missing OPENSSL_NO_ENGINE guard https://github.com/nodejs/node/pull/57012 * test,crypto: make tests work for BoringSSL https://github.com/nodejs/node/pull/57021 * module: use synchronous hooks for preparsing in import(cjs) https://github.com/nodejs/node/pull/55698 * deps: update simdjson to 3.12.0 https://github.com/nodejs/node/pull/56874 * build: remove explicit linker call to libm on macOS https://github.com/nodejs/node/pull/56901 * test: make eval snapshot comparison more flexible https://github.com/nodejs/node/pull/57020 * src: allow embedder customization of OOMErrorHandler https://github.com/nodejs/node/pull/57325 * src: do not pass nullptr to std::string ctor https://github.com/nodejs/node/pull/57354 * build: fix GN build failure * build: fix patch indices * crypto: expose security levels https://github.com/nodejs/node/pull/56601 * zlib: add zstd support https://github.com/nodejs/node/pull/52100 * test: move crypto related common utilities in common/crypto https://github.com/nodejs/node/pull/56714 * test: disable test-https-client-renegotiation-limit BoringSSL doesn't support caller-initiated renegotiation - see https://source.chromium.org/chromium/chromium/src/+/main:third_party/boringssl/src/ssl/ssl_lib.cc;l=1627-1631 * chore: fixup indices --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2025-05-13 21:56:52 +09:00
@@ -625,7 +626,8 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
return;
}
CompressionStream* ctx = static_cast<CompressionStream*>(data);
- char* real_pointer = static_cast<char*>(pointer) - sizeof(size_t);
+ constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t));
+ char* real_pointer = static_cast<char*>(pointer) - offset;
size_t real_size = *reinterpret_cast<size_t*>(real_pointer);
ctx->unreported_allocations_.fetch_sub(real_size,
std::memory_order_relaxed);