-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option for truncated stream detection #75671
Conversation
Tagging subscribers to this area: @dotnet/area-system-io-compression |
@@ -479,6 +478,8 @@ async Task<long> GetLengthAsync(CompressionLevel compressionLevel) | |||
[InlineData(TestScenario.ReadByteAsync)] | |||
public async Task StreamTruncation_IsDetected(TestScenario scenario) | |||
{ | |||
AppContext.SetSwitch("System.IO.Compression.UseStrictValidation", true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This affects all tests process-wide. Any test that changes such a process-wide switch needs to use RemoteExecutor to move that code out of process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is to create a second test project that enables the appcontext switch and runs all tests of the "normal" project with the switch on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And a third option could be to turn the switch on for all the tests, we already know our tests will pass with the "strict validation" in place.
I do prefer this option over the others but let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a third option could be to turn the switch on for all the tests, we already know our tests will pass with the "strict validation" in place.
Not anymore, this one will fail
runtime/src/libraries/System.IO.Compression/tests/CompressionStreamUnitTests.Deflate.cs
Line 78 in eead714
public void CompressorNotClosed_DecompressorStillSuccessful(bool closeCompressorBeforeDecompression) |
Another option is to create a second test project that enables the appcontext switch and runs all tests of the "normal" project with the switch on.
I prefer the current way (with the RemoteExecutor) but no strong feelings. Let me know.
src/libraries/Common/tests/System/IO/Compression/ZipTestHelper.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/tests/System/IO/Compression/ZipTestHelper.cs
Outdated
Show resolved
Hide resolved
...raries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliStream.Decompress.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs
Outdated
Show resolved
Hide resolved
move the test to concrete classes as abstracted classes are not supported by RemoteExecutor
break; | ||
|
||
ac = await ast.ReadAtLeastAsync(ad, 4096); | ||
bc = await bst.ReadAtLeastAsync(bd, 4096); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably you want to pass throwOnEndOfStream:false for both of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.. thanks.
bd = NormalizeLineEndings(bd); | ||
} | ||
|
||
AssertExtensions.SequenceEqual(ad, bd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And these should be sliced, e.g. ad.AsSpan(0, ac), bd.AsSpan(0, bc)
.
If this is just copying what's already there for the sync implementation, then maybe inputs just aren't triggering the faulty behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sync implementation is also not triggering any exception (when enabling strict validation) in the current version of the code. If I recall correctly I added this async version to cover the async code path while putting together the previous PR.
But since it appears to not trigger the truncated exception (anymore), it may be outside the scope of this PR to improve the test coverage for the async code path.
@@ -227,9 +234,15 @@ private bool TryDecompress(Span<byte> destination, out int bytesWritten) | |||
return false; | |||
} | |||
|
|||
private static readonly bool UseStrictValidation = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UseStrictValidation => s_useStrictValidation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
CI is fixed. Feel free to let me know what you prefer regarding #75671 (comment) and if anyone has any other feedback regarding this PR. |
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/tests/CompressionStreamUnitTests.ZLib.cs
Show resolved
Hide resolved
src/libraries/System.IO.Compression/tests/CompressionStreamUnitTests.Gzip.cs
Show resolved
Hide resolved
I believe I've addressed most concerns. Do you have any more feedback on this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
CI issue looks unrelated to this PR.
Having another go at #47563 (previous #61768)
This time using an opt-in flag to avoid breakage like this #72726.
/cc @jozkee