Pasting NULL bytes into textarea fails
Categories
(Core :: Widget: Gtk, defect, P3)
Tracking
()
People
(Reporter: xan, Assigned: stransky)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0
Steps to reproduce:
My users need to paste strings that include NULL characters into Firefox texareas.
Actual results:
The pasted data was cut off at the first NULL byte.
Expected results:
Almost anything else: include the NULL characters, ignore the NULL characters, replace them with the replacement character. Cutting off is the worst thing to do.
Reporter | ||
Comment 1•2 years ago
|
||
I have created a test page that describes and demonstrates the issue:
https://biblionix.xyz/pasting_null_bytes/
Chrome seems to handle the situation without issue.
Reporter | ||
Comment 2•2 years ago
|
||
Background: my users are copying the source of their Amazon "order details" page for processing by my web-based service. Amazon recently started including NULL bytes in this order details file. Of course this is beyond my control!
Comment 3•2 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::Widget: Gtk' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Reporter | ||
Comment 4•6 months ago
|
||
Is there any reason not to skip over \x00 bytes in textareas, rather than truncating at such bytes?
Assignee | ||
Comment 5•6 months ago
|
||
How do you get the string with NULL characters to clipboard? I expect you use copy from any other web page? Can you attach exact reproduction steps? It may be an issue with bad string conversion when copy / paste from clipboard, we use UTF-8 and this bug may point to bad encoding.
May you try any older Firefox version? It may be a bug in our clipboard code.
Thanks.
Reporter | ||
Comment 6•3 months ago
|
||
What I'm attempting to do in the real world is process HTML from Amazon: I'm attempting to process the order details form to pick out what items were ordered. It works fine, except that the Amazon HTML includes NULL characters.
To reproduce:
- Visit https://biblionix.xyz/pasting_null_bytes/
- Open the link labeled "HTML" in a new tab
- View the source of that tab, observing that NULL characters are there
- Copy the entire source
- Go back to the https://biblionix.xyz/pasting_null_bytes/ tab and paste into the textarea
- Observe that the NULL characters and anything after them are missing
Removing the NULL characters is fine, but I don't see any reason to remove all the text after them too.
I'm sorry for the delay in reply, I missed the notification email and only happened to see you had commented here. I appreciate your help.
Reporter | ||
Comment 7•3 months ago
|
||
Correction to the above: it's not a form I'm processing in the real world, it's the "here's what you ordered" HTML page.
Assignee | ||
Comment 8•3 months ago
|
||
Where the null character come from? Is that UFT8 string which is wrongly considered as C string? Do you see the same behavior with wl-paste utility? (try to paste null character as utf8 string).
Assignee | ||
Updated•3 months ago
|
Reporter | ||
Comment 9•3 months ago
|
||
The NULL characters come from the source of a web page, in just the way they're being delivered via that "HTML" link on the test page.
I tried wl-paste. When I copy the HTML source and then run wl-paste, my terminal shows the text before and after the NULL characters. (I'm not entirely sure whether it includes them or not.) wl-paste | less shows the same. But if I do wl-paste > test.txt, then the resulting file is truncated at the first NULL character. The text after them is not included.
I tried Firefox 32 and observed the same issue. I wasn't immediately able to go farther back, since older versions don't work with the TLS version on this server. I can work around that to go farther back if it would be helpful.
I tried Chrome going back to version 37 and it has what I believe to be correct behavior: it strips out the NULL characters but still includes all the text afterwards.
I've been telling my customers who need to use this feature to install Chrome. :-(
Comment 10•3 months ago
|
||
What window manager are you using? Using Ubuntu 24.04.2 LTS and XFCE I'm able to copy and paste the entire text. It worked with Firefox release 138.0.1 and with Nightly 140.0a1.
Reporter | ||
Comment 11•3 months ago
|
||
I'm using KDE on Debian stable (bookworm), so I suppose the window manager is Kwin. I am running Wayland now. When first reporting this, I believe I was on bullseye which was Xorg.
I tested Firefox on Windows (via BrowserStack) and the problem appeared all the way back to version 32, the oldest I could easily go.
Assignee | ||
Updated•3 months ago
|
Assignee | ||
Comment 12•3 months ago
|
||
I think we're hitting wrong text MIME type here where UTF8 is processed as plain C strings.
Assignee | ||
Comment 13•3 months ago
|
||
I can reproduce it. There's the related log:
[Parent 18296: Main Thread]: D/WidgetClipboard ClipboardDataSnapshot::GetDataSync: 7f7f2e6650c0
[Parent 18296: Main Thread]: D/WidgetClipboard nsClipboard::GetNativeClipboardData (clipboard)
[Parent 18296: Main Thread]: D/WidgetClipboard Flavors which can be imported:
[Parent 18296: Main Thread]: D/WidgetClipboard text/plain
[Parent 18296: Main Thread]: D/WidgetClipboard Getting text text/plain MIME clipboard data
[Parent 18296: Main Thread]: D/WidgetClipboard nsRetrievalContextWayland::GetClipboardText(), clipboard Selection
[Parent 18296: Main Thread]: D/WidgetClipboard nsRetrievalContextWayland::WaitForClipboardData, MIME (null)
[Parent 18296: Main Thread]: D/WidgetClipboard getting TEXT
[Parent 18296: Main Thread]: D/WidgetClipboard clipboard_get_cb() callback
[Parent 18296: Main Thread]: D/WidgetClipboard nsClipboard::SelectionGetEvent (clipboard)
[Parent 18296: Main Thread]: D/WidgetClipboard selection target text/plain;charset=utf-8
[Parent 18296: Main Thread]: D/WidgetClipboard providing text/plain data
[Parent 18296: Main Thread]: D/WidgetClipboard sent 115 bytes of utf-8 data
[Parent 18296: Main Thread]: D/WidgetClipboard using gtk_selection_data_set for 'text/plain;charset=utf-8'
[Parent 18296: Main Thread]: D/WidgetClipboard OnTextReceived(clipboard) callback
[Parent 18296: Main Thread]: D/WidgetClipboard Request::Complete(), aData = 7f7f2ed5a000, timedOut = 0
[Parent 18296: Main Thread]: D/WidgetClipboard getting 68 bytes of text.
[Parent 18296: Main Thread]: D/WidgetClipboard done, mClipboardData = 7f7f2a094650
[Parent 18296: Main Thread]: D/WidgetClipboard SetTransferableData MIME text/plain
[Parent 18296: Main Thread]: D/WidgetClipboard got text data, length 68
[Parent 18296: Main Thread]: D/WidgetClipboard clipboard_clear_cb() callback
[Parent 18296: Main Thread]: D/WidgetClipboard nsClipboard::SelectionClearEvent (primary)
[Parent 18296: Main Thread]: D/WidgetClipboard nsRetrievalContext::ClearCachedTargetsPrimary()
The problem is that we set UTF8 string in one tab as clipboard source but we paste it in another tab as text/plain which is C string and that's truncated then.
Assignee | ||
Updated•3 months ago
|
Assignee | ||
Comment 14•3 months ago
|
||
Also looks like wl-paste correctly pastes clipboard content while Firefox truncates it.
Assignee | ||
Updated•3 months ago
|
Assignee | ||
Comment 15•3 months ago
|
||
Xan, do you say it's broken on Windows too?
Assignee | ||
Comment 16•3 months ago
|
||
Chrome works because it removes all null chars from the page - it ignores them completely. I wonder if Firefox can do the same.
Assignee | ||
Comment 17•3 months ago
|
||
There are two possible fixes on Firefox side:
- Ignore null chars when we paste to clipboard (from the HTML page?). I wonder why we paste nullptr to clipboard or show them at all?
- Filter out what we get from clibpboard (null UTF-8 can be insterted by third-party app). It can be fixed by getting text as data as Gtk receives all text strings as null terminated.
Assignee | ||
Comment 18•3 months ago
|
||
UTF8 string can contain null characters which can be received by gtk_clipboard_request_text() as it returns C string terminated by null char.
Use gtk_clipboard_request_contents() instead and convert it to UTF16 (internal Firefox string format) directly.
Updated•3 months ago
|
Assignee | ||
Updated•3 months ago
|
Reporter | ||
Comment 19•3 months ago
|
||
(In reply to Martin Stránský [:stransky] (ni? me) from comment #15)
Xan, do you say it's broken on Windows too?
Yes, I observed the same problem on Windows.
Comment 20•3 months ago
|
||
Assignee | ||
Comment 21•3 months ago
|
||
Please file a new bug for Windows. Linux one should be fixed by the patch here.
Comment 22•3 months ago
|
||
Comment 23•3 months ago
|
||
Backed out for causing bc failures at browser_bookmark_copy_folder_tree.js
Reporter | ||
Comment 24•3 months ago
|
||
(In reply to Martin Stránský [:stransky] (ni? me) from comment #21)
Please file a new bug for Windows. Linux one should be fixed by the patch here.
I've created https://bugzilla.mozilla.org/show_bug.cgi?id=1966443
I also tried it on MacOS, and there does not seem to be a problem there. The NULL bytes are included, which is different from how Chrome handles it, but that isn't a problem for my use case at least.
Assignee | ||
Comment 25•3 months ago
|
||
[task 2025-05-14T10:17:56.316Z] 10:17:56 INFO - TEST-UNEXPECTED-FAIL | browser/components/places/tests/browser/browser_bookmark_copy_folder_tree.js | "toolbar\r\nmainFolder\r\nFolderA\r\nsubFolderA\r\nhttps://example.com/1\r\nhttps://example.com/2\r\nhttps://example.com/3\r\nFolderA\r\nsubFolderA\r\nhttps://example.com/1\r\nhttps://example.com/2\r\nhttps://example.com/3\r\nToolbar shortcut\r\n" == "toolbar\nmainFolder\nFolderA\nsubFolderA\nhttps://example.com/1\nhttps://example.com/2\nhttps://example.com/3\nFolderA\nsubFolderA\nhttps://example.com/1\nhttps://example.com/2\nhttps://example.com/3\nToolbar shortcut\n" -
Comment 26•2 months ago
|
||
There is an r+ patch which didn't land and no activity in this bug for 2 weeks.
:stransky, could you have a look please?
If you still have some work to do, you can add an action "Plan Changes" in Phabricator.
For more information, please visit BugBot documentation.
Assignee | ||
Comment 28•2 months ago
|
||
Looks like Windows version on this was also backed out (Bug 1966443).
Assignee | ||
Comment 29•2 months ago
|
||
I wonder if we need a kind of sanitation of input string instead of the plain UTF8 conversion.
Reporter | ||
Comment 30•1 month ago
|
||
Update: over at the Windows version of this bug, a patch has been posted with description containing " This patch skips NUL bytes on all platforms when adding to the clipboard or when dragging text from Firefox. This normalizes the behavior across platforms"
https://bugzilla.mozilla.org/show_bug.cgi?id=1966443#c15
That might make this bug moot (even though this is the original).
Assignee | ||
Comment 31•1 month ago
|
||
(In reply to Xan Charbonnet from comment #30)
Update: over at the Windows version of this bug, a patch has been posted with description containing " This patch skips NUL bytes on all platforms when adding to the clipboard or when dragging text from Firefox. This normalizes the behavior across platforms"
https://bugzilla.mozilla.org/show_bug.cgi?id=1966443#c15That might make this bug moot (even though this is the original).
Yes, that may be the best solution here, Thanks!
Description
•