-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't read past end of scratch buffer (#26)
When the incoming input buffer is short, we must make sure that we properly set inputLimitMinMaxTagLength to prevent buffer overruns. Otherwise we'll read past the end of the buffer. Close #25
- Loading branch information
1 parent
c9ddcf0
commit 6876d6e
Showing
2 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Snappier.Internal; | ||
using Xunit; | ||
|
||
namespace Snappier.Tests.Internal | ||
{ | ||
public class SnappyDecompressorTests | ||
{ | ||
#region DecompressAllTags | ||
|
||
[Fact] | ||
public void DecompressAllTags_ShortInputBufferWhichCopiesToScratch_DoesNotReadPastEndOfScratch() | ||
{ | ||
// Arrange | ||
|
||
var decompressor = new SnappyDecompressor(); | ||
decompressor.SetExpectedLengthForTest(1024); | ||
|
||
decompressor.WriteToBufferForTest(Enumerable.Range(0, 255).Select(p => (byte) p).ToArray()); | ||
|
||
// if in error, decompressor will read the 222, 0, 0 as the next tag and throw a copy offset exception | ||
decompressor.LoadScratchForTest(new byte[] { 222, 222, 222, 222, 0, 0 }, 0); | ||
|
||
// Act | ||
|
||
decompressor.DecompressAllTags(new byte[] { 150, 255, 0 }); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters