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

Side by Side Diff: Source/core/html/parser/TextResourceDecoder.cpp

Issue 23532016: Handle odd data lengths in UTF-16 decoder (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Simplify 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Document.cpp ('k') | Source/modules/encoding/TextDecoder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All rights reserved. 3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All rights reserved.
4 Copyright (C) 2005, 2006, 2007 Alexey Proskuryakov (ap@nypop.com) 4 Copyright (C) 2005, 2006, 2007 Alexey Proskuryakov (ap@nypop.com)
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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 WTF::TextEncoding detectedEncoding; 399 WTF::TextEncoding detectedEncoding;
400 if (detectTextEncoding(data, len, m_hintEncoding, &detectedEncoding)) 400 if (detectTextEncoding(data, len, m_hintEncoding, &detectedEncoding))
401 setEncoding(detectedEncoding, EncodingFromContentSniffing); 401 setEncoding(detectedEncoding, EncodingFromContentSniffing);
402 } 402 }
403 403
404 ASSERT(m_encoding.isValid()); 404 ASSERT(m_encoding.isValid());
405 405
406 if (!m_codec) 406 if (!m_codec)
407 m_codec = newTextCodec(m_encoding); 407 m_codec = newTextCodec(m_encoding);
408 408
409 String result = m_codec->decode(dataForDecode, lengthForDecode, false, m_con tentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); 409 String result = m_codec->decode(dataForDecode, lengthForDecode, DoNotFlush, m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError);
410 410
411 m_buffer.clear(); 411 m_buffer.clear();
412 return result; 412 return result;
413 } 413 }
414 414
415 String TextResourceDecoder::flush() 415 String TextResourceDecoder::flush()
416 { 416 {
417 // If we can not identify the encoding even after a document is completely 417 // If we can not identify the encoding even after a document is completely
418 // loaded, we need to detect the encoding if other conditions for 418 // loaded, we need to detect the encoding if other conditions for
419 // autodetection is satisfied. 419 // autodetection is satisfied.
420 if (m_buffer.size() && shouldAutoDetect() 420 if (m_buffer.size() && shouldAutoDetect()
421 && ((!m_checkedForXMLCharset && (m_contentType == HTMLContent || m_conte ntType == XMLContent)) || (!m_checkedForCSSCharset && (m_contentType == CSSConte nt)))) { 421 && ((!m_checkedForXMLCharset && (m_contentType == HTMLContent || m_conte ntType == XMLContent)) || (!m_checkedForCSSCharset && (m_contentType == CSSConte nt)))) {
422 WTF::TextEncoding detectedEncoding; 422 WTF::TextEncoding detectedEncoding;
423 if (detectTextEncoding(m_buffer.data(), m_buffer.size(), m_hintEncoding, &detectedEncoding)) 423 if (detectTextEncoding(m_buffer.data(), m_buffer.size(), m_hintEncoding, &detectedEncoding))
424 setEncoding(detectedEncoding, EncodingFromContentSniffing); 424 setEncoding(detectedEncoding, EncodingFromContentSniffing);
425 } 425 }
426 426
427 if (!m_codec) 427 if (!m_codec)
428 m_codec = newTextCodec(m_encoding); 428 m_codec = newTextCodec(m_encoding);
429 429
430 String result = m_codec->decode(m_buffer.data(), m_buffer.size(), true, m_co ntentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); 430 String result = m_codec->decode(m_buffer.data(), m_buffer.size(), FetchEOF, m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError);
431 m_buffer.clear(); 431 m_buffer.clear();
432 m_codec.clear(); 432 m_codec.clear();
433 m_checkedForBOM = false; // Skip BOM again when re-decoding. 433 m_checkedForBOM = false; // Skip BOM again when re-decoding.
434 return result; 434 return result;
435 } 435 }
436 436
437 } 437 }
OLDNEW
« no previous file with comments | « Source/core/dom/Document.cpp ('k') | Source/modules/encoding/TextDecoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698