fix: sanitize sixel previews#2542
Conversation
veltza
left a comment
There was a problem hiding this comment.
Do we really need sixel filtering in lf, given that terminals ignore invalid sixel characters anyway? My concern is that complex filtering will only increase CPU usage and further slow down sixel images.
Its not about invalid characters but malicious terminal sequences. The way sixel works in lf is that lf detects sixel based on the start byte and then passes all data directly to the terminal raw. That means sequences like OSC52 are interpreted by (all) terminals and overwrites your clipboard with something like When you expect something else in your clipboard, pasting that into a terminal and pressing enter is a likely risk
The performance impact is hardly even measurable and should be below 1ms even on slow hardware. |
Of course, control characters need to be checked. But can't you do that by checking that the sixel character is printable like the previous code did with
Do preload threads perform this complex filtering as well? If so, does that affect performance? |
Thats a good idea, I went ahead and implemented it.
yes, all sixel parsing is filtered. I did measure the performance and it has effectively no measurable impact. |
|
@joelim-work You implemented sixel if I recall. Does this look like a reasonable solution for you? |
|
Cleaned up the leftover code from previous approaches. Should be good now |
joelim-work
left a comment
There was a problem hiding this comment.
Looks good, thanks.
For the reocrd, I was able to reproduce this using the following previewer script:
#!/bin/sh
printf '\ePq"1;1;1;1 \e]52;c;%s\e\\ \e\\' "$(echo 'Hello, world!' | base64)"
Just to be sure, this does appear to be fully sanitized when used as lf previewer when I tested it. Or did it overwrite the clipboard for you? |
I tested against both the original version and with your changes. The original version actually processes the OSC 52 sequence and writes to the clipboard, while your version aborts processing the sixel sequence after encountering BTW I think it would be a good idea to include a simple test case like that in PR descriptions to make it easier for others to reproduce and verify that the patch actually addresses the issue. |
This patch now ensures that sixel parsing cannot include illegal sequences which are then written to the terminal.
Basically it checks if the sixel data contains only sequences that are valid base don the sixel specification