common: fix ASan error on non-null-terminated (16 char long) texture names
This commit is contained in:
parent
0215d52301
commit
14d4e91b82
22
common/fs.cc
22
common/fs.cc
|
|
@ -159,8 +159,24 @@ struct wad_archive : archive_like
|
|||
uint8_t compression;
|
||||
padding<2> pad;
|
||||
std::array<char, 16> name; // must be null terminated
|
||||
// NOTE: textures using all 16 exist in the wild, e.g. openquartzmirror
|
||||
// in free_wad.wad
|
||||
|
||||
auto stream_data() { return std::tie(filepos, disksize, size, type, compression, pad, name); }
|
||||
|
||||
std::string name_as_string() const {
|
||||
size_t length = 0;
|
||||
|
||||
// count the number of leading non-null characters
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
if (name[i] != 0)
|
||||
++length;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return std::string(name.data(), length);
|
||||
}
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::tuple<uint32_t, uint32_t>, case_insensitive_hash, case_insensitive_equal>
|
||||
|
|
@ -189,7 +205,11 @@ struct wad_archive : archive_like
|
|||
|
||||
wadstream >= file;
|
||||
|
||||
files[file.name.data()] = std::make_tuple(file.filepos, file.disksize);
|
||||
std::string tex_name = file.name_as_string();
|
||||
if (tex_name.size() == 16) {
|
||||
logging::print("WARNING: texture name {} ({}) is not null-terminated\n", tex_name, pathname);
|
||||
}
|
||||
files[tex_name] = std::make_tuple(file.filepos, file.disksize);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue