Closed Bug 1966443 Opened 6 months ago Closed 3 months ago

Pasting NULL bytes into textarea fails on Windows

Categories

(Core :: Widget: Win32, defect)

Firefox 138
defect

Tracking

()

VERIFIED FIXED
143 Branch
Tracking Status
firefox140 --- wontfix
firefox143 --- verified

People

(Reporter: xan, Assigned: handyman)

References

Details

Attachments

(6 files, 2 obsolete files)

54.24 KB, image/png
Details
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

Steps to reproduce:

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.

This same issue is occurring on Linux, and being addressed in https://bugzilla.mozilla.org/show_bug.cgi?id=1852790 .

The issue does not seem to occur on MacOS.

Component: Untriaged → DOM: Copy & Paste and Drag & Drop
Product: Firefox → Core

(In reply to Xan Charbonnet from comment #0)

This same issue is occurring on Linux, and being addressed in https://bugzilla.mozilla.org/show_bug.cgi?id=1852790 .
The issue does not seem to occur on MacOS.

This is likely a platform dependent bug.

Component: DOM: Copy & Paste and Drag & Drop → Widget: Win32
Severity: -- → S4

Hey Martin, this was pretty minor on Windows -- it boiled down to ignoring the comment and using allocLen instead of strlen here. However, this leaves the nulls in the string, so they are converted in HTML as I would expect (see the screen shot). Is this what you are doing in bug 1852790 or are you manually removing the nulls? Do you know what Mac did and do you think it matters if we have parity across platforms here?

Assignee: nobody → davidp99
Flags: needinfo?(stransky)

NULLs are expected in the clipboard data. Clipboard code tries to use
spans in a lot of places but there is a lot of old string stuff remaining
as well.

(In reply to David Parks [:handyman] from comment #2)

Hey Martin, this was pretty minor on Windows -- it boiled down to ignoring the comment and using allocLen instead of strlen here. However, this leaves the nulls in the string, so they are converted in HTML as I would expect (see the screen shot). Is this what you are doing in bug 1852790 or are you manually removing the nulls?

Yes, I keep the string data as is even with the null chars inside so they're printed. So it's the same.

Do you know what Mac did and do you think it matters if we have parity across platforms here?

No idea, I don't have Mac available. Maybe Emilio may know?

Flags: needinfo?(stransky) → needinfo?(emilio)
Flags: needinfo?(emilio)

OK, I was mis-reading the comments in bug 1852790.

Attachment #9488209 - Attachment description: WIP: Bug 1966443: Use proper length for Windows clipboard elements r=#win-reviewers! → Bug 1966443: Use proper length for Windows clipboard elements r=#win-reviewers!
Attachment #9488209 - Attachment description: Bug 1966443: Use proper length for Windows clipboard elements r=#win-reviewers! → Bug 1966443: Use proper length for Windows clipboard elements r=#win-reviewers!,emilio!
Pushed by daparks@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a7594596cdb1 Use proper length for Windows clipboard elements r=win-reviewers,emilio,gstoll
Status: UNCONFIRMED → RESOLVED
Closed: 6 months ago
Resolution: --- → FIXED
Target Milestone: --- → 140 Branch
Regressions: 1968267
QA Whiteboard: [qa-triage-done-c141/b140][qa-ver-opt-c141/b140]
Regressions: 1969820

Reproduced the issue using the info from comment 0 using an old Nightly build from 2025-05-14, verified that using the latest Nightly 141.0a1 and Latest Firefox 140.0b4 builds on Windows 11 the issue is no longer reproducible. I get the same input in the textarea as in comment 3.

Status: RESOLVED → VERIFIED
QA Whiteboard: [qa-triage-done-c141/b140][qa-ver-opt-c141/b140] → [qa-triage-done-c141/b140][qa-ver-done-c141/b140]
Regressions: 1968744
Pushed by dmeehan@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/c94e6fe693aa https://hg.mozilla.org/releases/mozilla-beta/rev/34e1906ff4ba Revert "Bug 1966443: Use proper length for Windows clipboard elements r=win-reviewers,emilio,gstoll" for causing Bug 1968744

Backed out from beta for causing Bug 1968744

Status: VERIFIED → REOPENED
Ever confirmed: true
Resolution: FIXED → ---
Target Milestone: 140 Branch → ---
Attachment #9488209 - Flags: approval-mozilla-release+

There is an r+ patch which didn't land and no activity in this bug for 2 weeks.
:handyman, 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.

Flags: needinfo?(emilio)
Flags: needinfo?(davidp99)
Flags: needinfo?(emilio)
Attachment #9488209 - Attachment is obsolete: true
Flags: needinfo?(davidp99)

GTK and Windows don't allow NUL characters to appear in clipboard and DND text.
Text data is null-terminated there. 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 for clipboard views of text
data internal and external to Gecko, so we can make assumptions about safety.

The test has exceptions for the behavior of different platforms when copying
a string that only contains NUL characters. Android and Wayland behave
slightly differently than others but it is not an important edge case.

Windows and GTK null-terminate text flavors in clipboard and DND operations.
For other platforms, it sanitizes text to ensure that there are no surprise
NUL characters in it, since NSStrings and Java strings in general can.

On a related note, GTK expects text to be obtained with gtk_selection_data_get_text,
not gtk_selection_data_get_data (and it guarantees null-termination), so
this patch makes that change as well.

Depends on D256876

Attachment #9499899 - Attachment description: Bug 1966443: Ignore NULs in clipboard paste and DND drop operations r=#win-reviewers!,#geckoview-reviewers,stransky!,#mac-reviewers! → Bug 1966443: Ignore NULs in clipboard paste and DND drop operations r=#geckoview-reviewers,stransky!,#mac-reviewers!
Attachment #9499899 - Attachment description: Bug 1966443: Ignore NULs in clipboard paste and DND drop operations r=#geckoview-reviewers,stransky!,#mac-reviewers! → Bug 1966443: Ignore NULs in clipboard paste and DND drop operations r=#win-reviewers!,#geckoview-reviewers,stransky!,#mac-reviewers!
Attachment #9499898 - Attachment is obsolete: true

Windows and GTK do not allow NUL characters in text data types that appear
on the clipboard or in DND payloads. Mac and Android do not specify if this
is allowed but they use string types that permit it. This patch normalizes
behavior across platforms by removing NUL ('\0') characters from text
flavors in those cases.

The test has exceptions for the behavior of different platforms when copying
a string that only contains NUL characters. Android and Wayland behave
slightly differently than others but it is not an important edge case.

Depends on D256877

Uses spawnChrome from a content process to initiate synthesizeMockDragAndDrop
in the parent process. The checks in synthesizeMockDragAndDrop will not be
run since communicating back to content requires SpecialPowers. So, in plain
mochitests the function will only be useful for the plain test itself.
(For example, tests can easily intercept expected drag/drop events and perform
their own behaviors/checks there.)

This patch also removes some cruft from the test framework's implementation and
improves logging integration.

For test_contextmenu_chorded_buttons.html, the synthesized escape key was
not dismissing the contextmenu, and it was blocking an upcoming DND test
when run in automation. Switched to a left-mouse-click to close it, since
closing the contextmenu is not part of the test.

test_contextmenu_by_mouse_on_unix.html isn't causing any test problems but
it was leaving a context menu open as well (it didn't attempt to close it).

Depends on D256877

Pushed by daparks@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/9e6fb6b2f02e https://hg.mozilla.org/integration/autoland/rev/e734223328db Make synthesizeMockDragAndDrop usable in plain mochitests r=edgar https://github.com/mozilla-firefox/firefox/commit/220cc239d38b https://hg.mozilla.org/integration/autoland/rev/02c254294b0b Ignore NULs in clipboard paste and DND drop operations r=stransky,geckoview-reviewers,mac-reviewers,bradwerth,tcampbell https://github.com/mozilla-firefox/firefox/commit/a2ba53f019c2 https://hg.mozilla.org/integration/autoland/rev/81265929e4e2 Clean up after tests that open context menus r=masayuki https://github.com/mozilla-firefox/firefox/commit/1affb70ae6b3 https://hg.mozilla.org/integration/autoland/rev/1dc105b7f065 Skip NUL characters in text that is copied to clipboard or dragged r=gstoll,dom-core,edgar
Pushed by ctuns@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/a9badb5d6ffc https://hg.mozilla.org/integration/autoland/rev/8e1ec242b1b5 Revert "Bug 1966443: Skip NUL characters in text that is copied to clipboard or dragged r=gstoll,dom-core,edgar" for causing mochitest failures in test_dnd_ignoreNuls.html

Backed out for causing mochitest failures

Flags: needinfo?(davidp99)

This is also a failure line: TEST-UNEXPECTED-FAIL | browser/components/urlbar/tests/browser/browser_removeUnsafeProtocolsFromURLBarPaste.js | Timed out while polling clipboard for requested data, got:

https://firefoxci.taskcluster-artifacts.net/Y5RZyzgkRGWFsh7jmRyBeg/0/public/logs/live_backing.log

DND might be the async timeout stuff -- that was initially believed to resolve intermittent Linux failures.

Flags: needinfo?(davidp99)

Failure is across platforms... but only for xorigin? That certainly shouldn't be related but maybe this is something to do with content transforms not being shared.

This patch series normalizes platforms so none support nulls.

Depends on D258092

Pushed by daparks@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/a19cb49fcdf2 https://hg.mozilla.org/integration/autoland/rev/d6d5319bb59e Make synthesizeMockDragAndDrop usable in plain mochitests r=edgar https://github.com/mozilla-firefox/firefox/commit/0d1a2059a278 https://hg.mozilla.org/integration/autoland/rev/0369759ab5f6 Ignore NULs in clipboard paste and DND drop operations r=stransky,geckoview-reviewers,mac-reviewers,bradwerth,tcampbell https://github.com/mozilla-firefox/firefox/commit/78a878bac037 https://hg.mozilla.org/integration/autoland/rev/2bca432ed2cb Clean up after tests that open context menus r=masayuki https://github.com/mozilla-firefox/firefox/commit/c0b7f6e71382 https://hg.mozilla.org/integration/autoland/rev/510a3deecb0a Skip NUL characters in text that is copied to clipboard or dragged r=gstoll,dom-core,edgar https://github.com/mozilla-firefox/firefox/commit/40b2f29da4f2 https://hg.mozilla.org/integration/autoland/rev/f2dbb34f6867 Remove MacOS supportsNullBytes test from browser_removeUnsafeProtocolsFromURLBarPaste.js r=mac-reviewers,urlbar-reviewers,mstange,Standard8
QA Whiteboard: [qa-triage-done-c141/b140][qa-ver-done-c141/b140] → [qa-triage-done-c144/b143]

(In reply to Bogdan Maris, Desktop Test Engineering from comment #10)

Reproduced the issue using the info from comment 0 using an old Nightly build from 2025-05-14, verified that using the latest Nightly 141.0a1 and Latest Firefox 140.0b4 builds on Windows 11 the issue is no longer reproducible. I get the same input in the textarea as in comment 3.

Also verified as fixed using Firefox 143.0b2 on Windows 10 and 11.

Status: RESOLVED → VERIFIED
QA Whiteboard: [qa-triage-done-c144/b143] → [qa-triage-done-c144/b143][qa-ver-done-c144/b143]
Regressions: 1984125
No longer regressions: 1984125
QA Whiteboard: [qa-triage-done-c144/b143][qa-ver-done-c144/b143] → [qa-triage-done-c141/b140][qa-ver-done-c141/b140][qa-triage-done-c144/b143][qa-ver-done-c144/b143]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: