Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1444)

Side by Side Diff: Source/core/dom/CharacterData.cpp

Issue 188693007: Added checks for integer overflow conditions to deleteData and replaceData. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed typo Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 String newStr = m_data; 101 String newStr = m_data;
102 newStr.insert(data, offset); 102 newStr.insert(data, offset);
103 103
104 setDataAndUpdate(newStr, offset, 0, data.length(), recalcStyleBehavior); 104 setDataAndUpdate(newStr, offset, 0, data.length(), recalcStyleBehavior);
105 105
106 document().didInsertText(this, offset, data.length()); 106 document().didInsertText(this, offset, data.length());
107 } 107 }
108 108
109 void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionState& exceptionState, RecalcStyleBehavior recalcStyleBehavior) 109 void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionState& exceptionState, RecalcStyleBehavior recalcStyleBehavior)
110 { 110 {
111 if (offset > length()) { 111 const unsigned dataLength = length();
112
113 if (offset > dataLength) {
112 exceptionState.throwDOMException(IndexSizeError, "The offset " + String: :number(offset) + " is greater than the node's length (" + String::number(length ()) + ")."); 114 exceptionState.throwDOMException(IndexSizeError, "The offset " + String: :number(offset) + " is greater than the node's length (" + String::number(length ()) + ").");
113 return; 115 return;
114 } 116 }
115 117
118 if (count > (dataLength - offset)) {
sof 2014/03/19 11:40:18 If not already, you may want to consider handling
119 exceptionState.throwDOMException(IndexSizeError, "Cannot delete " + Stri ng::number(count) + " characters, this is greater than the node's length with th e given offset.");
120 return;
121 }
122
116 unsigned realCount; 123 unsigned realCount;
117 if (offset + count > length()) 124 if (offset + count > dataLength)
118 realCount = length() - offset; 125 realCount = dataLength - offset;
119 else 126 else
120 realCount = count; 127 realCount = count;
121 128
122 String newStr = m_data; 129 String newStr = m_data;
123 newStr.remove(offset, realCount); 130 newStr.remove(offset, realCount);
124 131
125 setDataAndUpdate(newStr, offset, count, 0, recalcStyleBehavior); 132 setDataAndUpdate(newStr, offset, count, 0, recalcStyleBehavior);
126 133
127 document().didRemoveText(this, offset, realCount); 134 document().didRemoveText(this, offset, realCount);
128 } 135 }
129 136
130 void CharacterData::replaceData(unsigned offset, unsigned count, const String& d ata, ExceptionState& exceptionState) 137 void CharacterData::replaceData(unsigned offset, unsigned count, const String& d ata, ExceptionState& exceptionState)
131 { 138 {
132 if (offset > length()) { 139 const unsigned dataLength = length();
140
141 if (offset > dataLength) {
133 exceptionState.throwDOMException(IndexSizeError, "The offset " + String: :number(offset) + " is greater than the node's length (" + String::number(length ()) + ")."); 142 exceptionState.throwDOMException(IndexSizeError, "The offset " + String: :number(offset) + " is greater than the node's length (" + String::number(length ()) + ").");
134 return; 143 return;
135 } 144 }
136 145
146 if (count > (dataLength - offset)) {
147 exceptionState.throwDOMException(IndexSizeError, "Cannot replace " + Str ing::number(count) + " characters, this is greater than the node's length with t he given offset.");
148 return;
149 }
150
137 unsigned realCount; 151 unsigned realCount;
138 if (offset + count > length()) 152 if (offset + count > dataLength)
139 realCount = length() - offset; 153 realCount = dataLength - offset;
140 else 154 else
141 realCount = count; 155 realCount = count;
142 156
143 String newStr = m_data; 157 String newStr = m_data;
144 newStr.remove(offset, realCount); 158 newStr.remove(offset, realCount);
145 newStr.insert(data, offset); 159 newStr.insert(data, offset);
146 160
147 setDataAndUpdate(newStr, offset, count, data.length()); 161 setDataAndUpdate(newStr, offset, count, data.length());
148 162
149 // update the markers for spell checking and grammar checking 163 // update the markers for spell checking and grammar checking
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 { 219 {
206 return static_cast<int>(length()); 220 return static_cast<int>(length());
207 } 221 }
208 222
209 bool CharacterData::offsetInCharacters() const 223 bool CharacterData::offsetInCharacters() const
210 { 224 {
211 return true; 225 return true;
212 } 226 }
213 227
214 } // namespace WebCore 228 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698