Skip to content

Decompiling binaries with bitfield struct members causes crash #157

Description

@kumarak

Decompiling binaries with bitfield struct members crashes with:

   libc++abi: terminating due to uncaught exception of type std::bad_cast: std::bad_cast

at TypeBuilder.cpp:403 during complete_definition() when processing composite types containing bitfield components.

Root Cause

Object slicing in CompositeType::AddComponents (include/patchestry/Ghidra/PcodeTypes.hpp:210):

void AddComponents(std::string &name, const VarnodeType &type, uint32_t offset) {
    components.emplace_back(
        Component(name, offset, std::make_shared<VarnodeType>(type))  // slices!
    );
}

std::make_shared<VarnodeType>(type) copy-constructs a base VarnodeType, discarding the BitFieldType subclass data (bit_offset, bit_size, base_type_). When complete_definition() later does dynamic_cast<const BitFieldType &>(*component.type), it fails because the stored object is a plain VarnodeType, not a BitFieldType.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions