Error when entering part of a two-byte symbol

Open
#5,132 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
csharp
Domain
cli

Research direction

Start by reproducing the crash with the listed PowerShell and PSReadLine versions, then trace the history-writing path named in the stack trace: WriteHistoryRange, IncrementalHistoryWrite, and MaybeAddToHistory. The fix is done when deleting part of the surrogate pair no longer crashes the terminal or history write, while normal history behavior remains intact.

Written by the indexing model from the issue text.

Description

Needs-Triage :mag:
Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.
Exception report
### Environment
PSReadLine: 2.4.5
PowerShell: 7.6.1
OS: Microsoft Windows 10.0.26100
BufferWidth: 102
BufferHeight: 51

Last 102 Keys:

 s t a r h s i Backspace Backspace Backspace h Backspace s h i p Spacebar e x p l a i n Enter
 Backspace  Enter
 \ u f 1 8 8 Enter
 e c g Backspace h o Spacebar \ u f 1 8 8 Enter
 e c g i Spacebar Backspace Backspace Backspace h o Spacebar  Enter
 e c h o Spacebar � � Enter
 e c h o Spacebar  Enter
 e c h o Spacebar � � Enter
 e c h o Spacebar � � Backspace Backspace Backspace Spacebar � � Enter
 UpArrow Backspace Enter


### Exception

System.Text.EncoderFallbackException: Unable to translate Unicode character \\uDB82 at index 5 to specified code page.
   at System.Text.EncoderExceptionFallbackBuffer.Fallback(Char charUnknown, Int32 index)
   at System.Text.Encoding.GetBytesWithFallback(ReadOnlySpan`1 chars, Int32 originalCharsLength, Span`1 bytes, Int32 originalBytesLength, EncoderNLS encoder, Boolean throwForDestinationOverflow)
   at System.Text.Encoding.GetBytesWithFallback(Char* pOriginalChars, Int32 originalCharCount, Byte* pOriginalBytes, Int32 originalByteCount, Int32 charsConsumedSoFar, Int32 bytesWrittenSoFar, EncoderNLS encoder)
   at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
   at System.IO.StreamWriter.Dispose(Boolean disposing)
   at System.IO.TextWriter.Dispose()
   at Microsoft.PowerShell.PSConsoleReadLine.<>c__DisplayClass104_0.<WriteHistoryRange>b__0()
   at Microsoft.PowerShell.PSConsoleReadLine.<>c__DisplayClass104_0.<WriteHistoryRange>b__0()
   at Microsoft.PowerShell.PSConsoleReadLine.WithHistoryFileMutexDo(Int32 timeout, Action action)
   at Microsoft.PowerShell.PSConsoleReadLine.WriteHistoryRange(Int32 start, Int32 end, Boolean overwritten)
   at Microsoft.PowerShell.PSConsoleReadLine.IncrementalHistoryWrite()
   at Microsoft.PowerShell.PSConsoleReadLine.MaybeAddToHistory(String result, List`1 edits, Int32 undoEditIndex, Boolean fromDifferentSession, Boolean fromInitialRead)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)
Screenshot
Image
Environment data
PS Version: 7.6.1
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.4.5
PSReadLine EditMode: Windows
OS: 10.0.26100.1 (WinBuild.160101.0800)
BufferWidth: 102
BufferHeight: 51
Steps to reproduce
  1. Write echo 󰨰 in the terminal. The character code is \udb82\ude30
  2. Press up and delete the second char of the two byte symbol.
  3. Crash.
Expected behavior

No crash.

Actual behavior

Crash.

Dominant language
C#
Stars
4.4k
Forks
341
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PowerShell/PSReadLine

All issues in PowerShell/PSReadLine

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.