-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-System.Text.Encodingbugin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Description
Certain byte sequences causes certain encoders to throw NREs instead of overflow exceptions.
Reproduction Steps
using System;
using System.Text;
var str = "😀";
var encoding = Encoding.Unicode;
var bytes = encoding.GetBytes(str);
var decoder = encoding.GetDecoder();
var chars = new char[0];
decoder.Convert(bytes.AsSpan(), chars.AsSpan(), true, out _, out _, out var completed);Expected behavior
Expecting the same exception as something like this gives:
var str = "件";
...Actual behavior
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at System.Text.UnicodeEncoding.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, DecoderNLS baseDecoder)
at System.Text.DecoderNLS.Convert(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, Boolean flush, Int32& bytesUsed, Int32& charsUsed, Boolean& completed)
at System.Text.Decoder.Convert(ReadOnlySpan`1 bytes, Span`1 chars, Boolean flush, Int32& bytesUsed, Int32& charsUsed, Boolean& completed)
Regression?
No response
Known Workarounds
No response
Configuration
macOS Ventura, 8.0 preview 7
Other information
UTF32 shares the same issue, throwing an NRE, UTF8 is working correctly.
Metadata
Metadata
Assignees
Labels
area-System.Text.Encodingbugin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged