Fix case where if uncompressed map size was longer than actual map volume, would cause the client to Mono to infinitely loop. (Thanks mhsjlw)

This commit is contained in:
UnknownShadow200 2016-08-20 10:38:33 +10:00
parent 874de2ce9b
commit 443c520bd0
3 changed files with 7 additions and 8 deletions

View File

@ -238,7 +238,7 @@ namespace Ionic.Zlib {
}
internal void InflateTreesDynamic(int nl, int nd, int[] c, ref int bl, ref int bd,
ref int tl, ref int td, int[] hp, ZlibCodec z) {
ref int tl, ref int td, int[] hp) {
// build literal/length tree
ResetWorkArea( 288 );
hn = 0;

View File

@ -308,7 +308,7 @@ namespace Ionic.Zlib
int tl = 0;
int td = 0;
inftree.InflateTreesDynamic(257 + (table & 0x1f), 1 + ((table >> 5) & 0x1f), blens,
ref bl, ref bd, ref tl, ref td, hufts, codec);
ref bl, ref bd, ref tl, ref td, hufts);
codes.Init(bl, bd, hufts, tl, hufts, td);
}
mode = InflateBlockMode.CODES;
@ -318,9 +318,7 @@ namespace Ionic.Zlib
UpdateState( bits, bitsNum, availIn, nextIn, q );
r = codes.Process(this, r);
if( r != RCode.StreamEnd ) {
return Flush(r);
}
if (r != RCode.StreamEnd) return Flush(r);
r = RCode.Okay;
nextIn = codec.NextIn;
@ -330,8 +328,7 @@ namespace Ionic.Zlib
q = writeAt;
m = q < readAt ? readAt - q - 1 : end - q;
if (last == 0)
{
if (last == 0) {
mode = InflateBlockMode.TYPE;
break;
}
@ -350,7 +347,7 @@ namespace Ionic.Zlib
goto case InflateBlockMode.DONE;
case InflateBlockMode.DONE:
return RanOutOfInput( bits, bitsNum, availIn, nextIn, q, r );
return RanOutOfInput( bits, bitsNum, availIn, nextIn, q, RCode.StreamEnd );
default:
throw new InvalidOperationException( "Invalid inflate block mode: " + mode );

View File

@ -52,6 +52,8 @@ namespace ClassicalSharp.Map {
this.Height = height;
this.Length = length;
IsNotLoaded = width == 0 || length == 0 || height == 0;
if( blocks.Length != (width * height * length) )
throw new InvalidOperationException( "Blocks array length does not match volume of map." );
if( Env.EdgeHeight == -1 ) Env.EdgeHeight = height / 2;
maxY = height - 1;