Fix ASAN heap-buffer-overflow in PixTests (#5974)

PixStructAnnotation tests were converting an IDxcBlobEncoding to a
std::string, but this isn't valid if the underlying object is an
InternalDxcBlobEncoding_Impl, which holds a buffer that may not be
null-terminated. Fix this by using the BlobToUtf8 helper, which handles
this case gracefully.

Fixes 23 ASAN failures.
This commit is contained in:
Antonio Maiorano 2023-11-07 10:44:50 -05:00 коммит произвёл GitHub
Родитель 620c29d278
Коммит 519dd5bd56
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 1 добавлений и 4 удалений

Просмотреть файл

@ -258,10 +258,7 @@ PassOutput RunAnnotationPasses(dxc::DxcDllSupport &dllSupport, IDxcBlob *dxil,
VERIFY_SUCCEEDED(pOptimizer->RunOptimizer(
dxil, Options.data(), Options.size(), &pOptimizedModule, &pText));
std::string outputText;
if (pText->GetBufferSize() != 0) {
outputText = reinterpret_cast<const char *>(pText->GetBufferPointer());
}
std::string outputText = BlobToUtf8(pText);
auto disasm = ToString(Disassemble(dllSupport, pOptimizedModule));