From bf2064f6509281153abe63c3f257f4808a8d35e6 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Fri, 21 Oct 2022 11:06:28 +0200 Subject: [PATCH] Fix heap-use-after-free when writing section index When writing the section index block, an additional entry was added to the index, potentially reallocating the vector containing the index. However, we previously took the address of the vector data in order to write the index, so that address is now invalid. Fix is by not adding the extra entry to the index. --- src/dwarfs/filesystem_writer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dwarfs/filesystem_writer.cpp b/src/dwarfs/filesystem_writer.cpp index 3ea034cc..70aacef5 100644 --- a/src/dwarfs/filesystem_writer.cpp +++ b/src/dwarfs/filesystem_writer.cpp @@ -383,7 +383,9 @@ void filesystem_writer_::write(folly::ByteRange range) { template void filesystem_writer_::write(fsblock const& fsb) { - push_section_index(fsb.type()); + if (fsb.type() != section_type::SECTION_INDEX) { + push_section_index(fsb.type()); + } write(fsb.header()); write(fsb.data());