Skip to content

Commit

Permalink
(ElgFormat.Reader): moved output bounds check into loop body.
Browse files Browse the repository at this point in the history
  • Loading branch information
morkt committed Jul 19, 2015
1 parent e6dd091 commit c8d7066
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions ArcFormats/ImageELG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ void UnpackPalette ()
void UnpackIndexed (byte[] output)
{
int dst = 0;
while (dst < m_output.Length)
for (;;)
{
byte flags = m_input.ReadByte();
if (0xff == flags)
if (0xff == flags || dst >= m_output.Length)
break;
int count, pos;

Expand Down Expand Up @@ -228,10 +228,10 @@ void UnpackIndexed (byte[] output)
void UnpackRGBA ()
{
int dst = 0;
while (dst < m_output.Length)
for (;;)
{
byte flags = m_input.ReadByte();
if (0xff == flags)
if (0xff == flags || dst >= m_output.Length)
break;
int count, pos, src;

Expand All @@ -255,7 +255,7 @@ void UnpackRGBA ()
if (0 != (flags & 0x20))
count = ((flags & 0x1f) << 8) + m_input.ReadByte() + 34;
else
count = (flags & 0x1f) + 2;
count = (flags & 0x1f) + 2;

byte b = m_input.ReadByte();
byte g = m_input.ReadByte();
Expand Down Expand Up @@ -354,10 +354,10 @@ void UnpackRGBA ()
public void UnpackAlpha ()
{
int dst = 3;
while (dst < m_output.Length)
for (;;)
{
byte flags = m_input.ReadByte();
if (0xff == flags)
if (0xff == flags || dst >= m_output.Length)
break;

int count, pos;
Expand Down Expand Up @@ -439,10 +439,10 @@ public void UnpackAlpha ()
void UnpackRGB ()
{
int dst = 0;
while (dst < m_output.Length)
for (;;)
{
byte flags = m_input.ReadByte();
if (0xff == flags)
if (0xff == flags || dst >= m_output.Length)
break;
int count, pos, src;
if (0 == (flags & 0xc0))
Expand Down

0 comments on commit c8d7066

Please sign in to comment.