Skip to content

Commit 4a5448f

Browse files
committed
Ensure at least one complete code point is converted. Fixes #974
1 parent be4e25f commit 4a5448f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/MySqlConnector/MySqlBulkCopy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,13 @@ static bool WriteSubstring(string value, ref int inputIndex, ref Encoder? utf8En
621621

622622
utf8Encoder ??= s_utf8Encoding.GetEncoder();
623623
#if NETSTANDARD1_3
624-
if (output.Length <= 4 && utf8Encoder.GetByteCount(value.ToCharArray(), inputIndex, 1, flush: false) > output.Length)
624+
if (output.Length < 4 && utf8Encoder.GetByteCount(value.ToCharArray(), inputIndex, Math.Min(2, nextIndex - inputIndex), flush: false) > output.Length)
625625
return false;
626626
var buffer = new byte[output.Length];
627627
utf8Encoder.Convert(value.ToCharArray(), inputIndex, nextIndex - inputIndex, buffer, 0, buffer.Length, nextIndex == value.Length, out var charsUsed, out var bytesUsed, out var completed);
628628
buffer.AsSpan().CopyTo(output);
629629
#else
630-
if (output.Length <= 4 && utf8Encoder.GetByteCount(value.AsSpan(inputIndex, 1), flush: false) > output.Length)
630+
if (output.Length < 4 && utf8Encoder.GetByteCount(value.AsSpan(inputIndex, Math.Min(2, nextIndex - inputIndex)), flush: false) > output.Length)
631631
return false;
632632
utf8Encoder.Convert(value.AsSpan(inputIndex, nextIndex - inputIndex), output, nextIndex == value.Length, out var charsUsed, out var bytesUsed, out var completed);
633633
#endif

0 commit comments

Comments
 (0)