summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-05-01 11:32:04 -0700
committerFangrui Song <i@maskray.me>2024-05-01 11:32:04 -0700
commit91fef0013f2668d1dc0623ede21cf4048d9a733e (patch)
tree3f6b56f49b918e516663c62d97094a5442ce62b3
parent1ca600586a61cee41e117a188d880417de3e1c00 (diff)
[ELF] Catch zlib deflateInit2 error
The function may return Z_MEM_ERROR or Z_STREAM_ERR. The former does not have a good way of testing. The latter will be possible with a pending change that allows setting the compression level, which will come with a test.
-rw-r--r--lld/ELF/OutputSections.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 3e58ed4bda2d..1b09e5b0a557 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -301,7 +301,11 @@ static SmallVector<uint8_t, 0> deflateShard(ArrayRef<uint8_t> in, int level,
// 15 and 8 are default. windowBits=-15 is negative to generate raw deflate
// data with no zlib header or trailer.
z_stream s = {};
- deflateInit2(&s, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
+ auto res = deflateInit2(&s, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
+ if (res != 0) {
+ errorOrWarn("--compress-sections: deflateInit2 returned " + Twine(res));
+ return {};
+ }
s.next_in = const_cast<uint8_t *>(in.data());
s.avail_in = in.size();