iemejia opened a new pull request, #3951:
URL: https://github.com/apache/avro/pull/3951

   ## What
   
   Every explicit `IConvertible.ToXxx(IFormatProvider)` implementation on 
`AvroDecimal` called `Convert.ToXxx(this, provider)`. Since `this` is an 
`IConvertible`, `Convert.ToXxx(IConvertible, provider)` calls straight back 
into the same `IConvertible.ToXxx(provider)` method → unbounded recursion → 
`StackOverflowException`, which is **uncatchable in .NET and crashes the 
process**.
   
   Reproducer (from the issue):
   ```csharp
   Convert.ToByte(new AvroDecimal(0)); // StackOverflowException
   ```
   This affected `ToBoolean, ToByte, ToDecimal, ToDouble, ToInt16/32/64, 
ToSByte, ToSingle, ToUInt16/32/64` and `ToString`.
   
   ## Fix
   
   `IConvertible.ToType(Type, provider)` is the only implementation that does 
real work (converts the unscaled/scaled value to a `decimal` and calls 
`Convert.ChangeType`). Route the 12 numeric/boolean conversions through it 
(preserving the `IFormatProvider`), and make `ToString(provider)` use the 
public `ToString()` override. No `Convert.To*(this, provider)` self-calls 
remain.
   
   ## Tests
   
   Adds `TestAvroDecimalIConvertibleDoesNotRecurse` exercising all conversions 
(each would previously overflow the stack). Full C# suite passes (**1528 
tests**, 0 failures).
   
   JIRA: https://issues.apache.org/jira/browse/AVRO-3569


-- 
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]

Reply via email to