diff options
| author | Jeroen Hofstee <jhofstee@victronenergy.com> | 2025-04-28 18:51:36 +0200 |
|---|---|---|
| committer | Armin Kuster <akuster808@gmail.com> | 2025-05-17 12:11:15 -0600 |
| commit | 54c92c9e89c4436092a4eba74c32807ce299fb09 (patch) | |
| tree | daf0ae11d3481dabf810aa61337968d76890848a /meta-oe/recipes-devtools/nodejs | |
| parent | 32169212d7bd3470e5b7781d1f36539fefce6623 (diff) | |
| download | meta-openembedded-54c92c9e89c4436092a4eba74c32807ce299fb09.tar.gz | |
nodejs: backport a patch to prevent brotli crashing nodejs
Brotli can crash nodejs (on ARM), because the memory allocated for
brotli wasn't properly aligned.
https://github.com/google/brotli/issues/1159
https://github.com/nodejs/node/commit/dc035bbc9b310ff8067bc0dad22230978489c061
Signed-off-by: Jeroen Hofstee <jhofstee@victronenergy.com>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Diffstat (limited to 'meta-oe/recipes-devtools/nodejs')
| -rw-r--r-- | meta-oe/recipes-devtools/nodejs/nodejs/zlib-fix-pointer-alignment.patch | 64 | ||||
| -rw-r--r-- | meta-oe/recipes-devtools/nodejs/nodejs_20.18.2.bb | 1 |
2 files changed, 65 insertions, 0 deletions
diff --git a/meta-oe/recipes-devtools/nodejs/nodejs/zlib-fix-pointer-alignment.patch b/meta-oe/recipes-devtools/nodejs/nodejs/zlib-fix-pointer-alignment.patch new file mode 100644 index 0000000000..824ff678c6 --- /dev/null +++ b/meta-oe/recipes-devtools/nodejs/nodejs/zlib-fix-pointer-alignment.patch | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | From bbcd1f33161fd9874e8a61999d2739b177f99723 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Jeroen Hofstee <jhofstee@victronenergy.com> | ||
| 3 | Date: Mon, 28 Apr 2025 14:21:44 +0000 | ||
| 4 | Subject: [PATCH] zlib: fix pointer alignment | ||
| 5 | MIME-Version: 1.0 | ||
| 6 | Content-Type: text/plain; charset=UTF-8 | ||
| 7 | Content-Transfer-Encoding: 8bit | ||
| 8 | |||
| 9 | The function AllocForBrotli prefixes the allocated memory with its | ||
| 10 | size, and returns a pointer to the region after it. This pointer can | ||
| 11 | however no longer be suitably aligned. Correct this by allocating | ||
| 12 | the maximum of the the size of the size_t and the max alignment. | ||
| 13 | |||
| 14 | On Arm 32bits the size_t is 4 bytes long, but the alignment is 8 for | ||
| 15 | some NEON instructions. When Brotli is compiled with optimizations | ||
| 16 | enabled newer GCC versions will use the NEON instructions and trigger | ||
| 17 | a bus error killing node. | ||
| 18 | |||
| 19 | see https://github.com/google/brotli/issues/1159 | ||
| 20 | |||
| 21 | PR-URL: https://github.com/nodejs/node/pull/57727 | ||
| 22 | Reviewed-By: Shelley Vohr <shelley.vohr@gmail.com> | ||
| 23 | Reviewed-By: Tobias Nießen <tniessen@tnie.de> | ||
| 24 | Reviewed-By: Daniel Lemire <daniel@lemire.me> | ||
| 25 | Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> | ||
| 26 | |||
| 27 | Upstream-Status: Backport [https://github.com/nodejs/node/commit/dc035bbc9b310ff8067bc0dad22230978489c061] | ||
| 28 | --- | ||
| 29 | src/node_zlib.cc | 8 +++++--- | ||
| 30 | 1 file changed, 5 insertions(+), 3 deletions(-) | ||
| 31 | |||
| 32 | diff --git a/src/node_zlib.cc b/src/node_zlib.cc | ||
| 33 | index 66370e41..a537e766 100644 | ||
| 34 | --- a/src/node_zlib.cc | ||
| 35 | +++ b/src/node_zlib.cc | ||
| 36 | @@ -493,20 +493,22 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork { | ||
| 37 | } | ||
| 38 | |||
| 39 | static void* AllocForBrotli(void* data, size_t size) { | ||
| 40 | - size += sizeof(size_t); | ||
| 41 | + constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t)); | ||
| 42 | + size += offset; | ||
| 43 | CompressionStream* ctx = static_cast<CompressionStream*>(data); | ||
| 44 | char* memory = UncheckedMalloc(size); | ||
| 45 | if (UNLIKELY(memory == nullptr)) return nullptr; | ||
| 46 | *reinterpret_cast<size_t*>(memory) = size; | ||
| 47 | ctx->unreported_allocations_.fetch_add(size, | ||
| 48 | std::memory_order_relaxed); | ||
| 49 | - return memory + sizeof(size_t); | ||
| 50 | + return memory + offset; | ||
| 51 | } | ||
| 52 | |||
| 53 | static void FreeForZlib(void* data, void* pointer) { | ||
| 54 | if (UNLIKELY(pointer == nullptr)) return; | ||
| 55 | CompressionStream* ctx = static_cast<CompressionStream*>(data); | ||
| 56 | - char* real_pointer = static_cast<char*>(pointer) - sizeof(size_t); | ||
| 57 | + constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t)); | ||
| 58 | + char* real_pointer = static_cast<char*>(pointer) - offset; | ||
| 59 | size_t real_size = *reinterpret_cast<size_t*>(real_pointer); | ||
| 60 | ctx->unreported_allocations_.fetch_sub(real_size, | ||
| 61 | std::memory_order_relaxed); | ||
| 62 | -- | ||
| 63 | 2.43.0 | ||
| 64 | |||
diff --git a/meta-oe/recipes-devtools/nodejs/nodejs_20.18.2.bb b/meta-oe/recipes-devtools/nodejs/nodejs_20.18.2.bb index 1f45c3ec66..bef62f88eb 100644 --- a/meta-oe/recipes-devtools/nodejs/nodejs_20.18.2.bb +++ b/meta-oe/recipes-devtools/nodejs/nodejs_20.18.2.bb | |||
| @@ -26,6 +26,7 @@ SRC_URI = "http://nodejs.org/dist/v${PV}/node-v${PV}.tar.xz \ | |||
| 26 | file://0001-liftoff-Correct-function-signatures.patch \ | 26 | file://0001-liftoff-Correct-function-signatures.patch \ |
| 27 | file://libatomic.patch \ | 27 | file://libatomic.patch \ |
| 28 | file://182d9c05e78.patch \ | 28 | file://182d9c05e78.patch \ |
| 29 | file://zlib-fix-pointer-alignment.patch \ | ||
| 29 | file://run-ptest \ | 30 | file://run-ptest \ |
| 30 | " | 31 | " |
| 31 | SRC_URI:append:class-target = " \ | 32 | SRC_URI:append:class-target = " \ |
