mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r15767) -Fix: infinite loop when skipping sprites when a GRF is invalid (or truncated).
This commit is contained in:
parent
f5cb1873d6
commit
9fd7774235
@ -80,8 +80,9 @@ static void CompactSpriteCache();
|
|||||||
* Skip the given amount of sprite graphics data.
|
* Skip the given amount of sprite graphics data.
|
||||||
* @param type the type of sprite (compressed etc)
|
* @param type the type of sprite (compressed etc)
|
||||||
* @param num the amount of sprites to skip
|
* @param num the amount of sprites to skip
|
||||||
|
* @return true if the data could be correctly skipped.
|
||||||
*/
|
*/
|
||||||
void SkipSpriteData(byte type, uint16 num)
|
bool SkipSpriteData(byte type, uint16 num)
|
||||||
{
|
{
|
||||||
if (type & 2) {
|
if (type & 2) {
|
||||||
FioSkipBytes(num);
|
FioSkipBytes(num);
|
||||||
@ -90,6 +91,7 @@ void SkipSpriteData(byte type, uint16 num)
|
|||||||
int8 i = FioReadByte();
|
int8 i = FioReadByte();
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
int size = (i == 0) ? 0x80 : i;
|
int size = (i == 0) ? 0x80 : i;
|
||||||
|
if (size > num) return false;
|
||||||
num -= size;
|
num -= size;
|
||||||
FioSkipBytes(size);
|
FioSkipBytes(size);
|
||||||
} else {
|
} else {
|
||||||
@ -99,6 +101,7 @@ void SkipSpriteData(byte type, uint16 num)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,9 +123,7 @@ static SpriteType ReadSpriteHeaderSkipData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
FioSkipBytes(7);
|
FioSkipBytes(7);
|
||||||
SkipSpriteData(type, num - 8);
|
return SkipSpriteData(type, num - 8) ? ST_NORMAL : ST_INVALID;
|
||||||
|
|
||||||
return ST_NORMAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the given Sprite ID exists */
|
/* Check if the given Sprite ID exists */
|
||||||
|
Loading…
Reference in New Issue
Block a user