Skip to content

Commit 41ba31c

Browse files
author
apavlov@chromium.org
committed
Revert "Rewrite parseFrameSetListOfDimension to match HTML5"
The change has resulted in ASAN failures: http://build.chromium.org/p/chromium.webkit/builders/WebKit%20Linux%20ASAN/builds/7635/steps/webkit_tests/logs/stdio ==2535==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x604000176835 at pc 0x5b315d5 bp 0x7fffeec0d570 sp 0x7fffeec0d568 READ of size 1 at 0x604000176835 thread T0 (content_shell) #0 0x5b315d4 in WebCore::Length WebCore::parseDimension<unsigned char>(unsigned char const*, unsigned long, unsigned long) ../third_party/WebKit/Source/core/html/HTMLDimension.cpp:62:0 #1 0x5b3111b in WebCore::parseDimension(WTF::String const&, unsigned long, unsigned long) ../third_party/WebKit/Source/core/html/HTMLDimension.cpp:97:0 #2 0x5b30fab in WebCore::parseListOfDimensions(WTF::String const&) ../third_party/WebKit/Source/core/html/HTMLDimension.cpp:129:0 #3 0x5a4ae7f in WebCore::HTMLFrameSetElement::parseAttribute(WebCore::QualifiedName const&, WTF::AtomicString const&) ../third_party/WebKit/Source/core/html/HTMLFrameSetElement.cpp:84:0 This reverts commit ac7e5c0. TBR=jchaffraix@chromium.org Review URL: https://codereview.chromium.org/18565005 git-svn-id: svn://svn.chromium.org/blink/trunk@154013 bbb929c8-8fbe-4397-9dbb-9b2b20218538
1 parent 0a81ac4 commit 41ba31c

File tree

7 files changed

+122
-247
lines changed

7 files changed

+122
-247
lines changed

Source/core/core.gypi

-2
Original file line numberDiff line numberDiff line change
@@ -2069,8 +2069,6 @@
20692069
'html/HTMLDetailsElement.h',
20702070
'html/HTMLDialogElement.cpp',
20712071
'html/HTMLDialogElement.h',
2072-
'html/HTMLDimension.cpp',
2073-
'html/HTMLDimension.h',
20742072
'html/HTMLDirectoryElement.cpp',
20752073
'html/HTMLDirectoryElement.h',
20762074
'html/HTMLDivElement.cpp',

Source/core/html/HTMLDimension.cpp

-133
This file was deleted.

Source/core/html/HTMLDimension.h

-47
This file was deleted.

Source/core/html/HTMLFrameSetElement.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
#include "core/dom/MouseEvent.h"
3434
#include "core/dom/NodeRenderingContext.h"
3535
#include "core/html/HTMLCollection.h"
36-
#include "core/html/HTMLDimension.h"
3736
#include "core/html/HTMLFrameElement.h"
3837
#include "core/loader/FrameLoaderClient.h"
3938
#include "core/page/Frame.h"
39+
#include "core/platform/Length.h"
4040
#include "core/rendering/RenderFrameSet.h"
4141

4242
namespace WebCore {
@@ -81,12 +81,12 @@ void HTMLFrameSetElement::parseAttribute(const QualifiedName& name, const Atomic
8181
{
8282
if (name == rowsAttr) {
8383
if (!value.isNull()) {
84-
m_rowLengths = parseListOfDimensions(value.string());
84+
m_rowLengths = parseFrameSetListOfDimensions(value.string());
8585
setNeedsStyleRecalc();
8686
}
8787
} else if (name == colsAttr) {
8888
if (!value.isNull()) {
89-
m_colLengths = parseListOfDimensions(value.string());
89+
m_colLengths = parseFrameSetListOfDimensions(value.string());
9090
setNeedsStyleRecalc();
9191
}
9292
} else if (name == frameborderAttr) {

Source/core/platform/Length.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,36 @@ static Length parseHTMLAreaCoordinate(const CharType* data, unsigned length)
7373
return Length(0, Fixed);
7474
}
7575

76+
template<typename CharType>
77+
static Length parseFrameSetDimension(const CharType* data, unsigned length)
78+
{
79+
if (!length)
80+
return Length(1, Relative);
81+
82+
unsigned intLength;
83+
unsigned doubleLength;
84+
unsigned i = splitLength(data, length, intLength, doubleLength);
85+
86+
bool ok;
87+
CharType next = (i < length) ? data[i] : ' ';
88+
if (next == '%') {
89+
// IE quirk: accept decimal fractions for percentages.
90+
double r = charactersToDouble(data, doubleLength, &ok);
91+
if (ok)
92+
return Length(r, Percent);
93+
return Length(1, Relative);
94+
}
95+
int r = charactersToIntStrict(data, intLength, &ok);
96+
if (next == '*') {
97+
if (ok)
98+
return Length(r, Relative);
99+
return Length(1, Relative);
100+
}
101+
if (ok)
102+
return Length(r, Fixed);
103+
return Length(0, Relative);
104+
}
105+
76106
// FIXME: Per HTML5, this should follow the "rules for parsing a list of integers".
77107
Vector<Length> parseHTMLAreaElementCoords(const String& string)
78108
{
@@ -110,6 +140,43 @@ Vector<Length> parseHTMLAreaElementCoords(const String& string)
110140
return r;
111141
}
112142

143+
template<typename CharType>
144+
static Vector<Length> parseFrameSetListOfDimensionsInternal(StringImpl* str)
145+
{
146+
unsigned len = str->count(',') + 1;
147+
Vector<Length> r(len);
148+
149+
int i = 0;
150+
unsigned pos = 0;
151+
size_t pos2;
152+
153+
while ((pos2 = str->find(',', pos)) != notFound) {
154+
r[i++] = parseFrameSetDimension(str->getCharacters<CharType>() + pos, pos2 - pos);
155+
pos = pos2 + 1;
156+
}
157+
158+
ASSERT(i == len - 1);
159+
160+
// IE Quirk: If the last comma is the last char skip it and reduce len by one.
161+
if (str->length() - pos > 0)
162+
r[i] = parseFrameSetDimension(str->getCharacters<CharType>() + pos, str->length() - pos);
163+
else
164+
r.shrink(r.size() - 1);
165+
166+
return r;
167+
}
168+
169+
// FIXME: Per HTML5, this should "use the rules for parsing a list of dimensions".
170+
Vector<Length> parseFrameSetListOfDimensions(const String& string)
171+
{
172+
RefPtr<StringImpl> str = string.impl()->simplifyWhiteSpace();
173+
if (!str->length())
174+
return Vector<Length>();
175+
if (str->is8Bit())
176+
return parseFrameSetListOfDimensionsInternal<LChar>(str.get());
177+
return parseFrameSetListOfDimensionsInternal<UChar>(str.get());
178+
}
179+
113180
class CalculationValueHandleMap {
114181
WTF_MAKE_FAST_ALLOCATED;
115182
public:

Source/core/platform/Length.h

+1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ struct Length {
310310
};
311311

312312
Vector<Length> parseHTMLAreaElementCoords(const String&);
313+
Vector<Length> parseFrameSetListOfDimensions(const String&);
313314

314315
} // namespace WebCore
315316

0 commit comments

Comments
 (0)