fix incorrect item parsing in config.json

This commit is contained in:
Martin Michelsen
2023-12-28 10:41:59 -08:00
parent 1ba50e96ca
commit c1bcd45ea1
2 changed files with 7 additions and 17 deletions
+6
View File
@@ -647,6 +647,9 @@ bool ItemData::compare_for_sort(const ItemData& a, const ItemData& b) {
}
ItemData ItemData::from_data(const string& data) {
if (data.size() < 2) {
throw runtime_error("data is too short");
}
if (data.size() > 0x10) {
throw runtime_error("data is too long");
}
@@ -658,6 +661,9 @@ ItemData ItemData::from_data(const string& data) {
for (size_t z = 12; z < min<size_t>(data.size(), 16); z++) {
ret.data2[z - 12] = data[z];
}
if (ret.data1[0] > 4) {
throw runtime_error("invalid item class");
}
return ret;
}
+1 -17
View File
@@ -371,23 +371,7 @@ ItemData ItemNameIndex::parse_item_description(Version version, const std::strin
ret = this->parse_item_description_phase(version, desc, true);
} catch (const exception& e2) {
try {
string data = parse_data_string(desc);
if (data.size() < 2) {
throw runtime_error("item code too short");
}
if (data[0] > 4) {
throw runtime_error("invalid item class");
}
if (data.size() > 16) {
throw runtime_error("item code too long");
}
if (data.size() <= 12) {
memcpy(ret.data1.data(), data.data(), data.size());
} else {
memcpy(ret.data1.data(), data.data(), 12);
memcpy(ret.data2.data(), data.data() + 12, data.size() - 12);
}
ret = ItemData::from_data(parse_data_string(desc));
} catch (const exception& ed) {
if (strcmp(e1.what(), e2.what())) {
throw runtime_error(string_printf("cannot parse item description \"%s\" in %s (as text 1: %s) (as text 2: %s) (as data: %s)",