mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-11-15 17:02:03 +00:00
Reject stalled BZip2 decoder states after corruption
This commit is contained in:
@@ -21,26 +21,24 @@ internal partial class CBZip2InputStream
|
||||
var retChar = currentChar;
|
||||
switch (currentState)
|
||||
{
|
||||
case START_BLOCK_STATE:
|
||||
break;
|
||||
case RAND_PART_A_STATE:
|
||||
break;
|
||||
case RAND_PART_B_STATE:
|
||||
await SetupRandPartBAsync(cancellationToken).ConfigureAwait(false);
|
||||
break;
|
||||
case RAND_PART_C_STATE:
|
||||
await SetupRandPartCAsync(cancellationToken).ConfigureAwait(false);
|
||||
break;
|
||||
case NO_RAND_PART_A_STATE:
|
||||
break;
|
||||
case NO_RAND_PART_B_STATE:
|
||||
await SetupNoRandPartBAsync(cancellationToken).ConfigureAwait(false);
|
||||
break;
|
||||
case NO_RAND_PART_C_STATE:
|
||||
await SetupNoRandPartCAsync(cancellationToken).ConfigureAwait(false);
|
||||
break;
|
||||
case START_BLOCK_STATE:
|
||||
case RAND_PART_A_STATE:
|
||||
case NO_RAND_PART_A_STATE:
|
||||
default:
|
||||
break;
|
||||
// Match ReadByte(): retries after a decoding error must not generate endless output.
|
||||
throw new InvalidFormatException("BZip2: invalid decoder state");
|
||||
}
|
||||
return retChar;
|
||||
}
|
||||
|
||||
@@ -263,26 +263,25 @@ internal partial class CBZip2InputStream : Stream
|
||||
var retChar = currentChar;
|
||||
switch (currentState)
|
||||
{
|
||||
case START_BLOCK_STATE:
|
||||
break;
|
||||
case RAND_PART_A_STATE:
|
||||
break;
|
||||
case RAND_PART_B_STATE:
|
||||
SetupRandPartB();
|
||||
break;
|
||||
case RAND_PART_C_STATE:
|
||||
SetupRandPartC();
|
||||
break;
|
||||
case NO_RAND_PART_A_STATE:
|
||||
break;
|
||||
case NO_RAND_PART_B_STATE:
|
||||
SetupNoRandPartB();
|
||||
break;
|
||||
case NO_RAND_PART_C_STATE:
|
||||
SetupNoRandPartC();
|
||||
break;
|
||||
case START_BLOCK_STATE:
|
||||
case RAND_PART_A_STATE:
|
||||
case NO_RAND_PART_A_STATE:
|
||||
default:
|
||||
break;
|
||||
// These transitional states can remain after a decoding error. A retry (including
|
||||
// entry disposal) must fail rather than return the same byte indefinitely.
|
||||
throw new InvalidFormatException("BZip2: invalid decoder state");
|
||||
}
|
||||
return retChar;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user