Skip to content

Commit b0e9fa9

Browse files
committed
Avoiding 0 byte reading from Stream. Issue #60.
This fix avoids 0 byte reading from source Stream to prevent unexpected InvalidOperationException on System.Net APIs. Original issue report was formed as pull-request, but fixes for issue #59 affects target source, so added new logic based on the idea of the pull request.
1 parent a0192ea commit b0e9fa9

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/MsgPack/ItemsUnpacker.Unpacking.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6485,6 +6485,12 @@ internal bool ReadSubtreeMessagePackExtendedTypeObject( out MessagePackExtendedT
64856485

64866486
private static void ReadBytes( Stream source, byte[] buffer, int offset, int expectedSize )
64876487
{
6488+
if ( expectedSize == 0 )
6489+
{
6490+
// Reading 0 byte from stream causes exception in some implementation (issue #60, reported from @odyth).
6491+
return;
6492+
}
6493+
64886494
var currentOffset = offset;
64896495
var reading = expectedSize;
64906496
while ( true )

src/MsgPack/Unpacking.ttinclude

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ private void WriteHelperMethods()
2121
#>
2222
private static void ReadBytes( Stream source, byte[] buffer, int offset, int expectedSize )
2323
{
24+
if ( expectedSize == 0 )
25+
{
26+
// Reading 0 byte from stream causes exception in some implementation (issue #60, reported from @odyth).
27+
return;
28+
}
29+
2430
var currentOffset = offset;
2531
var reading = expectedSize;
2632
while ( true )

0 commit comments

Comments
 (0)