Skip to content

Commit 91fef00

Browse files
committed
[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.
1 parent 1ca6005 commit 91fef00

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lld/ELF/OutputSections.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,11 @@ static SmallVector<uint8_t, 0> deflateShard(ArrayRef<uint8_t> in, int level,
301301
// 15 and 8 are default. windowBits=-15 is negative to generate raw deflate
302302
// data with no zlib header or trailer.
303303
z_stream s = {};
304-
deflateInit2(&s, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
304+
auto res = deflateInit2(&s, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
305+
if (res != 0) {
306+
errorOrWarn("--compress-sections: deflateInit2 returned " + Twine(res));
307+
return {};
308+
}
305309
s.next_in = const_cast<uint8_t *>(in.data());
306310
s.avail_in = in.size();
307311

0 commit comments

Comments
 (0)