(ElgFormat.Reader): moved output bounds check into loop body.

This commit is contained in:
morkt 2015-07-20 00:20:30 +04:00
parent e6dd091316
commit c8d7066f24

View File

@ -155,10 +155,10 @@ namespace GameRes.Formats.Lucifen
void UnpackIndexed (byte[] output) void UnpackIndexed (byte[] output)
{ {
int dst = 0; int dst = 0;
while (dst < m_output.Length) for (;;)
{ {
byte flags = m_input.ReadByte(); byte flags = m_input.ReadByte();
if (0xff == flags) if (0xff == flags || dst >= m_output.Length)
break; break;
int count, pos; int count, pos;
@ -228,10 +228,10 @@ namespace GameRes.Formats.Lucifen
void UnpackRGBA () void UnpackRGBA ()
{ {
int dst = 0; int dst = 0;
while (dst < m_output.Length) for (;;)
{ {
byte flags = m_input.ReadByte(); byte flags = m_input.ReadByte();
if (0xff == flags) if (0xff == flags || dst >= m_output.Length)
break; break;
int count, pos, src; int count, pos, src;
@ -255,7 +255,7 @@ namespace GameRes.Formats.Lucifen
if (0 != (flags & 0x20)) if (0 != (flags & 0x20))
count = ((flags & 0x1f) << 8) + m_input.ReadByte() + 34; count = ((flags & 0x1f) << 8) + m_input.ReadByte() + 34;
else else
count = (flags & 0x1f) + 2; count = (flags & 0x1f) + 2;
byte b = m_input.ReadByte(); byte b = m_input.ReadByte();
byte g = m_input.ReadByte(); byte g = m_input.ReadByte();
@ -354,10 +354,10 @@ namespace GameRes.Formats.Lucifen
public void UnpackAlpha () public void UnpackAlpha ()
{ {
int dst = 3; int dst = 3;
while (dst < m_output.Length) for (;;)
{ {
byte flags = m_input.ReadByte(); byte flags = m_input.ReadByte();
if (0xff == flags) if (0xff == flags || dst >= m_output.Length)
break; break;
int count, pos; int count, pos;
@ -439,10 +439,10 @@ namespace GameRes.Formats.Lucifen
void UnpackRGB () void UnpackRGB ()
{ {
int dst = 0; int dst = 0;
while (dst < m_output.Length) for (;;)
{ {
byte flags = m_input.ReadByte(); byte flags = m_input.ReadByte();
if (0xff == flags) if (0xff == flags || dst >= m_output.Length)
break; break;
int count, pos, src; int count, pos, src;
if (0 == (flags & 0xc0)) if (0 == (flags & 0xc0))