Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -115,6 +115,10 @@ if (Hdr->ch_type != ELFCOMPRESS_ZLIB) fatal(getName(this) + ": unsupported compression type"); + // We check that uncompressed section size is not greater than 2^40 + // because it seems to be reasonable limit to protect from broken inputs. + if (Hdr->ch_size > SIZE_MAX || Hdr->ch_size > 0x10000000000) + fatal(getName(this) + ": uncompressed section size is too large"); StringRef Buf((const char *)Data.data(), Data.size()); size_t UncompressedDataSize = Hdr->ch_size; Index: test/ELF/invalid/too-large-compressed-sec.s =================================================================== --- test/ELF/invalid/too-large-compressed-sec.s +++ test/ELF/invalid/too-large-compressed-sec.s @@ -0,0 +1,7 @@ +# REQUIRES: x86 + +## too-large-compressed-sec.elf contains compressed section +## with broken header containing huge uncompressed section size value. +# RUN: not ld.lld %S/Inputs/common-symbol-alignment.elf \ +# RUN: -o %t 2>&1 | FileCheck %s +# CHECK: uncompressed section size is too large