Closed Bug 892510 Opened 6 years ago Closed 6 years ago

Putting lots of spaces in a textarea hangs the browser

Categories

(Core :: Layout: Text and Fonts, defect)

22 Branch
x86_64
Windows 7
defect
Not set

Tracking

()

RESOLVED FIXED
mozilla25

People

(Reporter: donalduc, Assigned: bzbarsky)

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0 (Beta/Release)
Build ID: 20130618035212

Steps to reproduce:

By mistake I put a lot of spaces in a textarea. (A string about 2Mb long containing only spaces.)


Actual results:

Browser hangs.


Expected results:

This only happens if there are lots of spaces in the beginning of the string. If they are at the end  (some other character followed by lots of spaces) there is no problem. It doesn't matter if the string is put in a textarea using Javascript or the HTML contains a textarea with lots of spaces.

This hangs:
<textarea id="ta"></textarea>
<script type="text/javascript">
var s = " ";
for ( var i=0 ; i<21 ; i++ ) {
	s += s;
}
document.getElementById("ta").value = s;
</script>

This is ok:
<textarea id="ta"></textarea>
<script type="text/javascript">
var s = " ";
for ( var i=0 ; i<21 ; i++ ) {
	s += s;
}
document.getElementById("ta").value = "Lots of spaces: " + s;
</script>
Component: Untriaged → Editor
Product: Firefox → Core
Attached file Testcase
Attachment #774842 - Attachment mime type: text/plain → text/html
Component: Editor → Layout
Looks like we keep reflowing the element for some reason...
All the time is spent in nsGenericDOMDataNode::TextIsOnlyWhitespace, called from nsLineLayout::ReflowFrame.  Presumably each call scans the whole textnode...

I'm not sure whether we can make nsLineLayout call this less often, but maybe we can cache the boolean.
Status: UNCONFIRMED → NEW
Component: Layout → Layout: Text
Ever confirmed: true
This makes loading the testcase sorta-ok.

But if you then try to resize the textarea, you end up in textrun-construction hell...
Comment on attachment 775088 [details] [diff] [review]
Partial fix, sorta

I guess the textrun stuff should just be a separate bug.
Attachment #775088 - Flags: review?(bugs)
Assignee: nobody → bzbarsky
Whiteboard: [need review]
Attachment #775088 - Flags: review?(bugs) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/59aca91c0c00

I filed bug 895259 on the textrun issue.
Flags: in-testsuite?
Whiteboard: [need review]
Target Milestone: --- → mozilla25
https://hg.mozilla.org/mozilla-central/rev/59aca91c0c00
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.