Fix bounds checking in CMemoryWriteFile::seek

Thanks @sfan5 for patch: a3d848ff8b
Note I also modified the bounds checks for CMemoryReadFile once more to unify it with how Minetest fixed it. 
Due to some strange coincidence I had run into that bug yesterday for CMemoryReadFile and fixed it without realizing a fix was also part of a bunch of patches I had gotten 3 days earlier in the forum:
https://irrlicht.sourceforge.io/forum/viewtopic.php?f=2&t=52819&p=306518#p306518


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6352 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2022-04-21 20:39:31 +00:00
parent a48b3a8d00
commit 0317f678fb

View File

@ -52,15 +52,14 @@ bool CMemoryReadFile::seek(long finalPos, bool relativeMovement)
{ {
if (relativeMovement) if (relativeMovement)
{ {
const long newPos = Pos + finalPos; if (Pos + finalPos < 0 || Pos + finalPos > Len)
if (newPos > Len || newPos < 0)
return false; return false;
Pos += finalPos; Pos += finalPos;
} }
else else
{ {
if (finalPos > Len || finalPos < 0) if (finalPos < 0 || finalPos > Len)
return false; return false;
Pos = finalPos; Pos = finalPos;
@ -134,14 +133,14 @@ bool CMemoryWriteFile::seek(long finalPos, bool relativeMovement)
{ {
if (relativeMovement) if (relativeMovement)
{ {
if (Pos + finalPos > Len) if (Pos + finalPos < 0 || Pos + finalPos > Len)
return false; return false;
Pos += finalPos; Pos += finalPos;
} }
else else
{ {
if (finalPos > Len) if (finalPos < 0 || finalPos > Len)
return false; return false;
Pos = finalPos; Pos = finalPos;