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

Side by Side Diff: Source/modules/encoding/TextDecoder.cpp

Issue 23532016: Handle odd data lengths in UTF-16 decoder (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 7 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 String TextDecoder::decode(ArrayBufferView* input, const Dictionary& options, Ex ceptionState& es) 80 String TextDecoder::decode(ArrayBufferView* input, const Dictionary& options, Ex ceptionState& es)
81 { 81 {
82 bool stream = false; 82 bool stream = false;
83 options.get("stream", stream); 83 options.get("stream", stream);
84 84
85 const char* start = input ? static_cast<const char*>(input->baseAddress()) : 0; 85 const char* start = input ? static_cast<const char*>(input->baseAddress()) : 0;
86 size_t length = input ? input->byteLength() : 0; 86 size_t length = input ? input->byteLength() : 0;
87 87
88 bool flush = !stream; 88 bool flush = !stream;
89 89
90 // FIXME: Not all TextCodec implementations handle |flush| - notably TextCod ecUTF16
91 // ignores it and never flushes!
92
93 bool sawError = false; 90 bool sawError = false;
94 String s = m_codec->decode(start, length, flush, m_fatal, sawError); 91 String s = m_codec->decode(start, length, flush, m_fatal, sawError);
95 92
96 if (m_fatal && sawError) { 93 if (m_fatal && sawError) {
97 es.throwDOMException(EncodingError, "The encoded data was not valid."); 94 es.throwDOMException(EncodingError, "The encoded data was not valid.");
98 return String(); 95 return String();
99 } 96 }
100 97
101 if (!m_bomSeen && !s.isEmpty()) { 98 if (!m_bomSeen && !s.isEmpty()) {
102 m_bomSeen = true; 99 m_bomSeen = true;
103 String name(m_encoding.name()); 100 String name(m_encoding.name());
104 if ((name == "UTF-8" || name == "UTF-16LE" || name == "UTF-16BE") && s[0 ] == 0xFEFF) 101 if ((name == "UTF-8" || name == "UTF-16LE" || name == "UTF-16BE") && s[0 ] == 0xFEFF)
105 s.remove(0); 102 s.remove(0);
106 } 103 }
107 104
108 if (flush) 105 if (flush)
109 m_bomSeen = false; 106 m_bomSeen = false;
110 107
111 return s; 108 return s;
112 } 109 }
113 110
114 } // namespace WebCore 111 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698