Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra CR when getting file over SSH #201

Open
andyDoucette opened this issue Aug 12, 2024 · 3 comments
Open

Extra CR when getting file over SSH #201

andyDoucette opened this issue Aug 12, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@andyDoucette
Copy link

What happened? What is expected?

I put a file into snips.sh that had a single line with a \n character at the end (no \r).

On another system, I retrieved the file using ssh.

I compared the sha256 of the source and the retrieved file and they were not the same.

snips.sh seems to have added a \r before the \n. :(

I expect snips.sh not to change my files in any way whatsoever.

How can we reproduce it?

root@staging:/# echo 'hi' | od -a
0000000 h i nl
0000003

root@staging:/# echo 'hi' | ssh snips.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
┃ File Uploaded 📤
┃ id: qbH7FNuWG8
┃ size: 3 B • type: plaintext • visibility: public
┃ SSH 📠
┃ ssh f:qbH7FNuWG8@snips.sh
┃ URL 🔗
https://snips.sh/f/qbH7FNuWG8

root@staging:/# ssh f:qbH7FNuWG8@snips.sh | od -a
Connection to snips.sh closed.
0000000 h i cr nl
0000004

Anything else we need to know?

no

@andyDoucette andyDoucette added the bug Something isn't working label Aug 12, 2024
@robherley
Copy link
Owner

👋 I looked into this a bit.

If you download your file over curl, you'll notice that it's fine:

$ curl -s https://snips.sh/f/qbH7FNuWG8 | od -a
0000000    h   i  nl                                                    
0000003

However, the problem does come in when fetching over ssh:

$ ssh f:qbH7FNuWG8@snips.sh | od -a
0000000    h   i  cr  nl                                                
0000004

The SSH library that snips uses, (wish) is built on top of gliderlabs/ssh.

Within that library, I found the following: https://github.com/gliderlabs/ssh/blob/adec695b0aa80b0a03f251e1f8c302f0ea192ef5/session.go#L133-L137

// normalize \n to \r\n when pty is accepted.
// this is a hardcoded shortcut since we don't support terminal modes.
p = bytes.Replace(p, []byte{'\n'}, []byte{'\r', '\n'}, -1)
p = bytes.Replace(p, []byte{'\r', '\r', '\n'}, []byte{'\r', '\n'}, -1)

I'll look into this a bit more.

@robherley
Copy link
Owner

Looks like wish's ssh fork is doing something slightly different with a PtyWriter: https://github.com/charmbracelet/ssh/blob/eb71b85b27aa2fbecab39bbd5ba2cd6e7f4cab24/session.go#L144-L146

For now, you can disable pty allocation:

$ ssh -T f:qbH7FNuWG8@snips.sh | od -a
0000000    h   i  nl                                                    
0000003

@robherley robherley changed the title snips.sh is modifying files Extra CR when getting file over SSH Sep 13, 2024
@robherley
Copy link
Owner

Also updated the issue title to clarify the behavior we're seeing 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants