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.
Decompiling binaries with bitfield struct members crashes with:
at
TypeBuilder.cpp:403duringcomplete_definition()when processing composite types containing bitfield components.Root Cause
Object slicing in
CompositeType::AddComponents(include/patchestry/Ghidra/PcodeTypes.hpp:210):std::make_shared<VarnodeType>(type)copy-constructs a baseVarnodeType, discarding theBitFieldTypesubclass data (bit_offset,bit_size,base_type_). Whencomplete_definition()later doesdynamic_cast<const BitFieldType &>(*component.type), it fails because the stored object is a plainVarnodeType, not aBitFieldType.