Repository navigation
Fix decoding surrogates on error - #36159
Conversation
|
|
||
| // if that's all that was requested -> return | ||
| if (charCount == 0) | ||
| if (charCount + surrogateCount == 0) |
There was a problem hiding this comment.
It seems like the entirety of the fix could have been encapsulated by a one-line change:
if (charCount <= 0)Is it really expected that charCount could ever be negative?
There was a problem hiding this comment.
That would work for this scenario, but as I don't know all possible cases so added this new variable just to avoid from broking anything else.
Is it really expected that charCount could ever be negative?
I assume the person who wrote it wasn't expecting that, but it is becaming negative in case of surrogate chars
There was a problem hiding this comment.
I will update with your suggestion and run tests
There was a problem hiding this comment.
Right - I agree with your assessment that I don't think this number was intended to go negative. But with the proposed fix we still allow this to happen. If this behavior is indeed intentional, then a check for negative values should be sufficient to fix the bug. If the number's not intended to go negative, then it seems we need to tweak the fix further so that this condition doesn't occur.
There was a problem hiding this comment.
Seems main intention of this condition was only expected number of chars converted successfully. But the creator of this code didn't count surrogate chars case, so we might better to check if (i == 1 || i == 2) instead of if (charCount <= 0)
There was a problem hiding this comment.
Spoke with @buyaa-n offline. This type subclasses Decoder, but it doesn't properly fulfill the contract of Decoder.Convert and related methods. For example, it sets completed = true in some scenarios even when there's still unconsumed state in the decoder. The existing implementation of this type requires a much deeper investigation than this small handful of changes.
…codingSurrogatesOnError
Thank you @GrabYourPitchforks diggin into it and helping to find better solution Some test falilures on Linux seems not related merging Commit migrated from dotnet/corefx@004b31d
Fixes #35073