[
https://issues.apache.org/jira/browse/AVRO-3225?focusedWorklogId=664635&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-664635
]
ASF GitHub Bot logged work on AVRO-3225:
----------------------------------------
Author: ASF GitHub Bot
Created on: 13/Oct/21 13:21
Start Date: 13/Oct/21 13:21
Worklog Time Spent: 10m
Work Description: RyanSkraba commented on a change in pull request #1357:
URL: https://github.com/apache/avro/pull/1357#discussion_r728056320
##########
File path: lang/csharp/src/apache/test/IO/BinaryCodecTests.cs
##########
@@ -216,21 +217,98 @@ public void TestString(string n, int overhead)
#if NETCOREAPP3_1
[Test]
- public void TestLargeString()
+ public void TestStringReadIntoArrayPool()
{
+ const int maxFastReadLength = 4096;
+
// Create a 16KB buffer in the Array Pool
var largeBufferToSeedPool = ArrayPool<byte>.Shared.Rent(2 << 14);
ArrayPool<byte>.Shared.Return(largeBufferToSeedPool);
- // Create a slightly less than 16KB buffer, which will use the
16KB buffer in the pool
- var n = string.Concat(Enumerable.Repeat("1234567890", 1600));
- var overhead = 3;
+ var n = string.Concat(Enumerable.Repeat("A", maxFastReadLength));
+ var overhead = 2;
TestRead(n, (Decoder d) => d.ReadString(), (Encoder e, string t)
=> e.WriteString(t), overhead + n.Length);
- TestSkip(n, (Decoder d) => d.SkipString(), (Encoder e, string t)
=> e.WriteString(t), overhead + n.Length);
+ }
+
+ [Test]
+ public void TestStringReadByBinaryReader()
+ {
+ const int overhead = 2;
+ const int maxFastReadLength = 4096;
+ const int expectedStringLength = maxFastReadLength + 1;
+ var n = string.Concat(Enumerable.Repeat("A",
expectedStringLength));
+
+ TestRead(n, (Decoder d) => d.ReadString(), (Encoder e, string t)
=> e.WriteString(t), expectedStringLength + overhead);
}
#endif
+ [Test]
+ public void TestInvalidInputWithNegativeStringLength()
+ {
+ using (MemoryStream iostr = new MemoryStream())
+ {
+ Encoder e = new BinaryEncoder(iostr);
+
+ e.WriteLong(-1);
+
+ iostr.Flush();
+ iostr.Position = 0;
+ Decoder d = new BinaryDecoder(iostr);
+
+ var exception = Assert.Throws<AvroException>(() =>
d.ReadString());
+
+ Assert.NotNull(exception);
+ Assert.AreEqual("Can not deserialize a string with negative
length!", exception.Message);
+ iostr.Close();
+ }
+ }
+
+ [Test]
+ public void TestInvalidInputWithMaxIntAsStringLength()
+ {
+ using (MemoryStream iostr = new MemoryStream())
+ {
+ Encoder e = new BinaryEncoder(iostr);
+
+ e.WriteLong(int.MaxValue);
+ e.WriteBytes(Encoding.UTF8.GetBytes("SomeSmallString"));
+
+ iostr.Flush();
+ iostr.Position = 0;
+ Decoder d = new BinaryDecoder(iostr);
+
+ var exception = Assert.Throws<AvroException>(() =>
d.ReadString());
+
+ Assert.NotNull(exception);
+ Assert.AreEqual("String length is not supported!",
exception.Message);
+ iostr.Close();
+ }
+ }
+
+ [Test]
+ public void TestInvalidInputWithMaxArrayLengthAsStringLength()
Review comment:
Huh, that's confusing. According to
https://docs.microsoft.com/en-us/lifecycle/faq/dotnet-framework#what-is-the-lifecycle-policy-for-different-versions-of--net-framework-
there's quite a few supported versions in the 4.x range...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 664635)
Time Spent: 1h 10m (was: 1h)
> StackOverflowException on invalid input for BinaryDecoder.ReadString on
> NetStandard 2.1+
> ----------------------------------------------------------------------------------------
>
> Key: AVRO-3225
> URL: https://issues.apache.org/jira/browse/AVRO-3225
> Project: Apache Avro
> Issue Type: Bug
> Components: csharp
> Reporter: Philip Sanetra
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.11.0
>
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
> The BinaryDecoder.ReadString() method on NetStandard2.1+ produces a stack
> overflow exception if there is invalid input caused by this code:
>
> {code:java}
> int length = ReadInt();
> Span<byte> buffer = length <= StackallocThreshold ? stackalloc byte[length] :
> (bufferArray = ArrayPool<byte>.Shared.Rent(length)).AsSpan(0,
> length);
> {code}
>
> This code fails if ReadInt() returns a negative value.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)