Fix map tools crashing on maps with unknown UUID-based map items

All `map_*` tools were crashing with the assertion `Invalid type` when used on maps that contain unknown UUID-based map items. When the UUID cannot be resolved, the type `-1` is returned by the `GetItem` function. The assertion predates UUID map items, so this crash has likely existed since the introduction of UUID map items. The editor was not affected and has instead always discarded map items that it does not support. The tools will now also discard map items with unknown UUIDs.

See #7669.
This commit is contained in:
Robert Müller 2023-12-22 00:10:34 +01:00
parent d05269154e
commit a9e7926c29
6 changed files with 31 additions and 12 deletions

View file

@ -219,14 +219,15 @@ int main(int argc, const char **argv)
{
int Type, ID;
void *pItem = g_DataReader.GetItem(Index, &Type, &ID);
int Size = g_DataReader.GetItemSize(Index);
// filter ITEMTYPE_EX items, they will be automatically added again
if(Type == ITEMTYPE_EX)
// Filter items with unknown type, as we can't write them back.
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type < 0 || Type == ITEMTYPE_EX)
{
continue;
}
int Size = g_DataReader.GetItemSize(Index);
Success &= CheckImageDimensions(pItem, Type, pSourceFileName);
CMapItemImage NewImageItem;

View file

@ -377,8 +377,13 @@ void SaveOutputMap(CDataFileReader &InputMap, CDataFileWriter &OutputMap, CMapIt
int ID, Type;
void *pItem = InputMap.GetItem(i, &Type, &ID);
if(Type == ITEMTYPE_EX)
// Filter items with unknown type, as we can't write them back.
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type < 0 || Type == ITEMTYPE_EX)
{
continue;
}
if(i == NewItemNumber)
pItem = pNewItem;

View file

@ -140,13 +140,14 @@ int main(int argc, const char **argv)
{
int Type, ID;
void *pPtr = Reader.GetItem(Index, &Type, &ID);
int Size = Reader.GetItemSize(Index);
// filter ITEMTYPE_EX items, they will be automatically added again
if(Type == ITEMTYPE_EX)
// Filter items with unknown type, as we can't write them back.
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type < 0 || Type == ITEMTYPE_EX)
{
continue;
}
// for all layers, check if it uses a image and set the corresponding flag
if(Type == MAPITEMTYPE_LAYER)
{
@ -203,6 +204,7 @@ int main(int argc, const char **argv)
++i;
}
int Size = Reader.GetItemSize(Index);
Writer.AddItem(Type, ID, Size, pPtr);
}

View file

@ -168,8 +168,13 @@ void SaveOutputMap(CDataFileReader &InputMap, CDataFileWriter &OutputMap)
int ID, Type;
void *pItem = InputMap.GetItem(i, &Type, &ID);
if(Type == ITEMTYPE_EX)
// Filter items with unknown type, as we can't write them back.
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type < 0 || Type == ITEMTYPE_EX)
{
continue;
}
if(g_apNewItem[i])
pItem = g_apNewItem[i];

View file

@ -150,9 +150,12 @@ int main(int argc, const char **argv)
int Type, ID;
void *pItem = g_DataReader.GetItem(Index, &Type, &ID);
// filter ITEMTYPE_EX items, they will be automatically added again
if(Type == ITEMTYPE_EX)
// Filter items with unknown type, as we can't write them back.
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type < 0 || Type == ITEMTYPE_EX)
{
continue;
}
int Size = g_DataReader.GetItemSize(Index);

View file

@ -32,9 +32,12 @@ static int ResaveMap(const char *pSourceMap, const char *pDestinationMap, IStora
int Type, ID;
const void *pPtr = Reader.GetItem(Index, &Type, &ID);
// filter ITEMTYPE_EX items, they will be automatically added again
if(Type == ITEMTYPE_EX)
// Filter items with unknown type, as we can't write them back.
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type < 0 || Type == ITEMTYPE_EX)
{
continue;
}
int Size = Reader.GetItemSize(Index);
Writer.AddItem(Type, ID, Size, pPtr);