Changeset 31316 in webkit
- Timestamp:
- Mar 26, 2008 10:19:07 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r31313 r31316 1 2008-03-26 Eric Seidel <eric@webkit.org> 2 3 Reviewed by darin. 4 5 Fix, makes us pass Test 70 6 XML documents should be strict about encoding checks 7 http://bugs.webkit.org/show_bug.cgi?id=17079 8 9 * fast/encoding/invalid-xml-expected.txt: Added. 10 * fast/encoding/invalid-xml.html: Copied from LayoutTests/fast/dom/resources/TEMPLATE.html. 11 * fast/encoding/resources/invalid-xml-shift-jis.xml: Added. 12 * fast/encoding/resources/invalid-xml-utf16.xml: Added. 13 * fast/encoding/resources/invalid-xml-utf8.xml: Added. 14 * fast/encoding/resources/invalid-xml-x-mac-thai.xml: Added. 15 * fast/encoding/resources/invalid-xml.js: Added. 16 1 17 2008-03-26 Dan Bernstein <mitz@apple.com> 2 18 -
trunk/WebCore/ChangeLog
r31315 r31316 1 2008-03-26 Eric Seidel <eric@webkit.org> 2 3 Reviewed by darin. 4 5 Fix, makes us pass Test 70 6 XML documents should be strict about encoding checks 7 http://bugs.webkit.org/show_bug.cgi?id=17079 8 9 Test: fast/encoding/invalid-xml.html 10 11 * WebCore.base.exp: 12 * dom/XMLTokenizer.cpp: 13 (WebCore::XMLTokenizer::write): 14 * loader/CachedFont.cpp: 15 (WebCore::CachedFont::ensureSVGFontData): 16 * loader/TextResourceDecoder.cpp: 17 (WebCore::TextResourceDecoder::TextResourceDecoder): 18 (WebCore::TextResourceDecoder::decode): 19 * loader/TextResourceDecoder.h: 20 * platform/text/TextCodec.h: 21 (WebCore::TextCodec::decode): 22 * platform/text/TextCodecICU.cpp: 23 (WebCore::TextCodecICU::decodeToBuffer): 24 (WebCore::ErrorCallbackSetter::ErrorCallbackSetter): 25 (WebCore::ErrorCallbackSetter::~ErrorCallbackSetter): 26 (WebCore::TextCodecICU::decode): 27 * platform/text/TextCodecICU.h: 28 * platform/text/TextCodecLatin1.cpp: 29 * platform/text/TextCodecLatin1.h: 30 * platform/text/TextCodecUTF16.cpp: 31 * platform/text/TextCodecUTF16.h: 32 * platform/text/TextCodecUserDefined.cpp: 33 * platform/text/TextCodecUserDefined.h: 34 * platform/text/TextDecoder.cpp: 35 (WebCore::TextDecoder::checkForBOM): 36 * platform/text/TextDecoder.h: 37 (WebCore::TextDecoder::decode): 38 * platform/text/TextEncoding.cpp: 39 (WebCore::TextEncoding::decode): 40 * platform/text/TextEncoding.h: 41 (WebCore::TextEncoding::decode): 42 * platform/text/mac/TextCodecMac.cpp: 43 (WebCore::TextCodecMac::decode): 44 * platform/text/mac/TextCodecMac.h: 45 1 46 2008-03-26 Antti Koivisto <antti@apple.com> 2 47 -
trunk/WebCore/WebCore.base.exp
r31293 r31316 659 659 __ZNK7WebCore12SharedBuffer4dataEv 660 660 __ZNK7WebCore12SharedBuffer4sizeEv 661 __ZNK7WebCore12TextEncoding6decodeEPKcm 661 __ZNK7WebCore12TextEncoding6decodeEPKcmbRb 662 662 __ZNK7WebCore13HitTestResult10isLiveLinkEv 663 663 __ZNK7WebCore13HitTestResult10isSelectedEv -
trunk/WebCore/dom/XMLTokenizer.cpp
r30584 r31316 47 47 #include "ResourceRequest.h" 48 48 #include "ResourceResponse.h" 49 #include "TextResourceDecoder.h" 49 50 #ifndef USE_QXMLSTREAM 50 51 #include <libxml/parser.h> … … 669 670 #endif 670 671 672 if (m_doc->decoder() && m_doc->decoder()->sawError()) 673 // If the decoder saw an error, report it as fatal (stops parsing) 674 handleError(fatal, "Encoding error", lineNumber(), columnNumber()); 675 671 676 return false; 672 677 } -
trunk/WebCore/loader/CachedFont.cpp
r31287 r31316 138 138 TextResourceDecoder decoder("application/xml"); 139 139 m_externalSVGDocument->write(decoder.decode(m_data->data(), m_data->size())); 140 if (decoder.sawError()) { 141 m_externalSVGDocument.clear(); 142 return 0; 143 } 140 144 141 145 m_externalSVGDocument->finishParsing(); -
trunk/WebCore/loader/TextResourceDecoder.cpp
r30545 r31316 328 328 , m_checkedForCSSCharset(false) 329 329 , m_checkedForHeadCharset(false) 330 , m_sawError(false) 330 331 { 331 332 } … … 759 760 760 761 if (m_buffer.isEmpty()) 761 return m_decoder.decode(data, len );762 return m_decoder.decode(data, len, false, m_contentType == XML, m_sawError); 762 763 763 764 if (!movedDataToBuffer) { … … 767 768 } 768 769 769 String result = m_decoder.decode(m_buffer.data(), m_buffer.size() );770 String result = m_decoder.decode(m_buffer.data(), m_buffer.size(), false, m_contentType == XML, m_sawError); 770 771 m_buffer.clear(); 771 772 return result; … … 774 775 String TextResourceDecoder::flush() 775 776 { 776 String result = m_decoder.decode(m_buffer.data(), m_buffer.size(), true );777 String result = m_decoder.decode(m_buffer.data(), m_buffer.size(), true, m_contentType == XML, m_sawError); 777 778 m_buffer.clear(); 778 779 return result; -
trunk/WebCore/loader/TextResourceDecoder.h
r27776 r31316 53 53 String decode(const char* data, size_t length); 54 54 String flush(); 55 56 bool sawError() const { return m_sawError; } 55 57 56 58 private: … … 71 73 bool m_checkedForCSSCharset; 72 74 bool m_checkedForHeadCharset; 75 bool m_sawError; 73 76 }; 74 77 -
trunk/WebCore/platform/text/TextCodec.h
r31089 r31316 33 33 #include <wtf/unicode/Unicode.h> 34 34 35 #include "PlatformString.h" 36 35 37 namespace WebCore { 36 37 class CString;38 class String;39 38 class TextEncoding; 40 39 … … 61 60 virtual ~TextCodec(); 62 61 63 virtual String decode(const char*, size_t length, bool flush = false) = 0; 62 String decode(const char* str, size_t length, bool flush = false) 63 { 64 bool ignored; 65 return decode(str, length, flush, false, ignored); 66 } 67 68 virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError) = 0; 64 69 virtual CString encode(const UChar*, size_t length, UnencodableHandling) = 0; 65 70 -
trunk/WebCore/platform/text/TextCodecICU.cpp
r31089 r31316 216 216 } 217 217 218 String TextCodecICU::decode(const char* bytes, size_t length, bool flush) 218 int TextCodecICU::decodeToBuffer(UChar* target, UChar* targetLimit, const char*& source, const char* sourceLimit, int32_t* offsets, bool flush, UErrorCode& err) 219 { 220 UChar* targetStart = target; 221 err = U_ZERO_ERROR; 222 ucnv_toUnicode(m_converterICU, &target, targetLimit, &source, sourceLimit, offsets, flush, &err); 223 return target - targetStart; 224 } 225 226 class ErrorCallbackSetter { 227 public: 228 ErrorCallbackSetter(UConverter* converter, bool stopOnError) 229 : m_converter(converter) 230 , m_shouldStopOnEncodingErrors(stopOnError) 231 { 232 if (m_shouldStopOnEncodingErrors) { 233 UErrorCode err = U_ZERO_ERROR; 234 ucnv_setToUCallBack(m_converter, UCNV_TO_U_CALLBACK_SUBSTITUTE, 235 UCNV_SUB_STOP_ON_ILLEGAL, &m_savedAction, 236 &m_savedContext, &err); 237 ASSERT(err == U_ZERO_ERROR); 238 } 239 } 240 ~ErrorCallbackSetter() 241 { 242 if (m_shouldStopOnEncodingErrors) { 243 UErrorCode err = U_ZERO_ERROR; 244 const void* oldContext; 245 UConverterToUCallback oldAction; 246 ucnv_setToUCallBack(m_converter, m_savedAction, 247 m_savedContext, &oldAction, 248 &oldContext, &err); 249 ASSERT(oldAction == UCNV_TO_U_CALLBACK_SUBSTITUTE); 250 ASSERT(oldContext == UCNV_SUB_STOP_ON_ILLEGAL); 251 ASSERT(err == U_ZERO_ERROR); 252 } 253 } 254 private: 255 UConverter* m_converter; 256 bool m_shouldStopOnEncodingErrors; 257 const void* m_savedContext; 258 UConverterToUCallback m_savedAction; 259 }; 260 261 String TextCodecICU::decode(const char* bytes, size_t length, bool flush, bool stopOnError, bool& sawError) 219 262 { 220 263 // Get a converter for the passed-in encoding. … … 227 270 } 228 271 } 272 273 ErrorCallbackSetter callbackSetter(m_converterICU, stopOnError); 229 274 230 275 Vector<UChar> result; 231 276 232 277 UChar buffer[ConversionBufferSize]; 278 UChar* bufferLimit = buffer + ConversionBufferSize; 233 279 const char* source = reinterpret_cast<const char*>(bytes); 234 280 const char* sourceLimit = source + length; 235 281 int32_t* offsets = NULL; 236 UErrorCode err ;282 UErrorCode err = U_ZERO_ERROR; 237 283 238 284 do { 239 UChar* target = buffer; 240 const UChar* targetLimit = target + ConversionBufferSize; 241 err = U_ZERO_ERROR; 242 ucnv_toUnicode(m_converterICU, &target, targetLimit, &source, sourceLimit, offsets, flush, &err); 243 int count = target - buffer; 244 appendOmittingBOM(result, buffer, count); 285 int ucharsDecoded = decodeToBuffer(buffer, bufferLimit, source, sourceLimit, offsets, flush, err); 286 appendOmittingBOM(result, buffer, ucharsDecoded); 245 287 } while (err == U_BUFFER_OVERFLOW_ERROR); 246 288 … … 248 290 // flush the converter so it can be reused, and not be bothered by this error. 249 291 do { 250 UChar *target = buffer; 251 const UChar *targetLimit = target + ConversionBufferSize; 252 err = U_ZERO_ERROR; 253 ucnv_toUnicode(m_converterICU, &target, targetLimit, &source, sourceLimit, offsets, true, &err); 292 decodeToBuffer(buffer, bufferLimit, source, sourceLimit, offsets, true, err); 254 293 } while (source < sourceLimit); 294 sawError = true; 255 295 LOG_ERROR("ICU conversion error"); 256 return String();257 296 } 258 297 -
trunk/WebCore/platform/text/TextCodecICU.h
r31089 r31316 46 46 virtual ~TextCodecICU(); 47 47 48 virtual String decode(const char*, size_t length, bool flush = false);48 virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError); 49 49 virtual CString encode(const UChar*, size_t length, UnencodableHandling); 50 50 … … 54 54 bool needsGBKFallbacks() const { return m_needsGBKFallbacks; } 55 55 void setNeedsGBKFallbacks(bool needsFallbacks) { m_needsGBKFallbacks = needsFallbacks; } 56 57 int decodeToBuffer(UChar* buffer, UChar* bufferLimit, const char*& source, 58 const char* sourceLimit, int32_t* offsets, bool flush, UErrorCode& err); 56 59 57 60 TextEncoding m_encoding; -
trunk/WebCore/platform/text/TextCodecLatin1.cpp
r31089 r31316 119 119 } 120 120 121 String TextCodecLatin1::decode(const char* bytes, size_t length, bool )121 String TextCodecLatin1::decode(const char* bytes, size_t length, bool, bool, bool&) 122 122 { 123 123 StringBuffer characters(length); -
trunk/WebCore/platform/text/TextCodecLatin1.h
r31089 r31316 36 36 static void registerCodecs(TextCodecRegistrar); 37 37 38 virtual String decode(const char*, size_t length, bool flush = false);38 virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError); 39 39 virtual CString encode(const UChar*, size_t length, UnencodableHandling); 40 40 }; -
trunk/WebCore/platform/text/TextCodecUTF16.cpp
r31089 r31316 68 68 } 69 69 70 String TextCodecUTF16::decode(const char* bytes, size_t length, bool )70 String TextCodecUTF16::decode(const char* bytes, size_t length, bool, bool stopOnError, bool& sawError) 71 71 { 72 72 if (!length) -
trunk/WebCore/platform/text/TextCodecUTF16.h
r31089 r31316 38 38 TextCodecUTF16(bool littleEndian) : m_littleEndian(littleEndian), m_haveBufferedByte(false) { } 39 39 40 virtual String decode(const char*, size_t length, bool flush = false);40 virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError); 41 41 virtual CString encode(const UChar*, size_t length, UnencodableHandling); 42 42 -
trunk/WebCore/platform/text/TextCodecUserDefined.cpp
r31089 r31316 51 51 } 52 52 53 String TextCodecUserDefined::decode(const char* bytes, size_t length, bool )53 String TextCodecUserDefined::decode(const char* bytes, size_t length, bool, bool, bool&) 54 54 { 55 55 StringBuffer buffer(length); -
trunk/WebCore/platform/text/TextCodecUserDefined.h
r31089 r31316 36 36 static void registerCodecs(TextCodecRegistrar); 37 37 38 virtual String decode(const char*, size_t length, bool flush = false);38 virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError); 39 39 virtual CString encode(const UChar*, size_t length, UnencodableHandling); 40 40 }; -
trunk/WebCore/platform/text/TextDecoder.cpp
r28234 r31316 48 48 } 49 49 50 String TextDecoder::checkForBOM(const char* data, size_t length, bool flush )50 String TextDecoder::checkForBOM(const char* data, size_t length, bool flush, bool stopOnError, bool& sawError) 51 51 { 52 52 // Check to see if we found a BOM. … … 97 97 memcpy(bufferedBytes, m_bufferedBytes, numBufferedBytes); 98 98 m_numBufferedBytes = 0; 99 return m_codec->decode(bufferedBytes, numBufferedBytes, false) 100 + m_codec->decode(data, length, flush); 99 100 String bufferedResult = m_codec->decode(bufferedBytes, numBufferedBytes, false, stopOnError, sawError); 101 if (stopOnError && sawError) 102 return bufferedResult; 103 return bufferedResult + m_codec->decode(data, length, flush, stopOnError, sawError); 101 104 } 102 105 103 return m_codec->decode(data, length, flush );106 return m_codec->decode(data, length, flush, stopOnError, sawError); 104 107 } 105 108 -
trunk/WebCore/platform/text/TextDecoder.h
r28234 r31316 42 42 const TextEncoding& encoding() const { return m_encoding; }; 43 43 44 String decode(const char* data, size_t length, bool flush = false)44 String decode(const char* data, size_t length, bool flush, bool stopOnError, bool& sawError) 45 45 { 46 46 if (!m_checkedForBOM) 47 return checkForBOM(data, length, flush );48 return m_codec->decode(data, length, flush );47 return checkForBOM(data, length, flush, stopOnError, sawError); 48 return m_codec->decode(data, length, flush, stopOnError, sawError); 49 49 } 50 50 51 51 private: 52 String checkForBOM(const char*, size_t length, bool flush );52 String checkForBOM(const char*, size_t length, bool flush, bool stopOnError, bool& sawError); 53 53 54 54 TextEncoding m_encoding; -
trunk/WebCore/platform/text/TextEncoding.cpp
r31089 r31316 60 60 } 61 61 62 String TextEncoding::decode(const char* data, size_t length ) const62 String TextEncoding::decode(const char* data, size_t length, bool stopOnError, bool& sawError) const 63 63 { 64 64 if (!m_name) 65 65 return String(); 66 66 67 return TextDecoder(*this).decode(data, length, true );67 return TextDecoder(*this).decode(data, length, true, stopOnError, sawError); 68 68 } 69 69 -
trunk/WebCore/platform/text/TextEncoding.h
r31089 r31316 48 48 const TextEncoding& closest8BitEquivalent() const; 49 49 50 String decode(const char*, size_t length) const; 50 String decode(const char* str, size_t length) const 51 { 52 bool ignored; 53 return decode(str, length, false, ignored); 54 } 55 String decode(const char*, size_t length, bool stopOnError, bool& sawError) const; 51 56 CString encode(const UChar*, size_t length, UnencodableHandling) const; 52 57 -
trunk/WebCore/platform/text/mac/TextCodecMac.cpp
r31089 r31316 79 79 TextCodecMac::TextCodecMac(TECTextEncodingID encoding) 80 80 : m_encoding(encoding) 81 , m_error(false)82 81 , m_numBufferedBytes(0) 83 82 , m_converterTEC(0) … … 180 179 181 180 // Work around bug 3351093, where sometimes we get kTECBufferBelowMinimumSizeErr instead of kTECOutputBufferFullStatus. 182 if (status == kTECBufferBelowMinimumSizeErr && bytesWritten != 0) {181 if (status == kTECBufferBelowMinimumSizeErr && bytesWritten != 0) 183 182 status = kTECOutputBufferFullStatus; 184 }185 183 186 184 inputLength = bytesRead; … … 189 187 } 190 188 191 String TextCodecMac::decode(const char* bytes, size_t length, bool flush )189 String TextCodecMac::decode(const char* bytes, size_t length, bool flush, bool stopOnError, bool& sawError) 192 190 { 193 191 // Get a converter for the passed-in encoding. … … 202 200 UniChar buffer[ConversionBufferSize]; 203 201 204 while ( sourceLength || bufferWasFull) {202 while ((sourceLength || bufferWasFull) && !sawError) { 205 203 int bytesRead = 0; 206 204 int bytesWritten = 0; … … 218 216 // FIXME: Put FFFD character into the output string in this case? 219 217 TECClearConverterContextInfo(m_converterTEC); 218 if (stopOnError) { 219 sawError = true; 220 break; 221 } 220 222 if (sourceLength) { 221 223 sourcePointer += 1; … … 238 240 default: 239 241 LOG_ERROR("text decoding failed with error %ld", static_cast<long>(status)); 240 m_error = true;242 sawError = true; 241 243 return String(); 242 244 } -
trunk/WebCore/platform/text/mac/TextCodecMac.h
r31089 r31316 44 44 virtual ~TextCodecMac(); 45 45 46 virtual String decode(const char*, size_t length, bool flush = false);46 virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError); 47 47 virtual CString encode(const UChar*, size_t length, UnencodableHandling); 48 48 … … 56 56 TECTextEncodingID m_encoding; 57 57 UChar m_backslashAsCurrencySymbol; 58 bool m_error;59 58 unsigned m_numBufferedBytes; 60 59 unsigned char m_bufferedBytes[16]; // bigger than any single multi-byte character
Note: See TracChangeset
for help on using the changeset viewer.