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

Side by Side Diff: Source/wtf/text/TextCodecICU.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/wtf/text/TextCodecICU.h ('k') | Source/wtf/text/TextCodecLatin1.h » ('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) 2004, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> 3 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com>
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 330 }
331 } 331 }
332 332
333 private: 333 private:
334 UConverter* m_converter; 334 UConverter* m_converter;
335 bool m_shouldStopOnEncodingErrors; 335 bool m_shouldStopOnEncodingErrors;
336 const void* m_savedContext; 336 const void* m_savedContext;
337 UConverterToUCallback m_savedAction; 337 UConverterToUCallback m_savedAction;
338 }; 338 };
339 339
340 String TextCodecICU::decode(const char* bytes, size_t length, bool flush, bool s topOnError, bool& sawError) 340 String TextCodecICU::decode(const char* bytes, size_t length, FlushBehavior flus h, bool stopOnError, bool& sawError)
341 { 341 {
342 // Get a converter for the passed-in encoding. 342 // Get a converter for the passed-in encoding.
343 if (!m_converterICU) { 343 if (!m_converterICU) {
344 createICUConverter(); 344 createICUConverter();
345 ASSERT(m_converterICU); 345 ASSERT(m_converterICU);
346 if (!m_converterICU) { 346 if (!m_converterICU) {
347 WTF_LOG_ERROR("error creating ICU encoder even though encoding was i n table"); 347 WTF_LOG_ERROR("error creating ICU encoder even though encoding was i n table");
348 return String(); 348 return String();
349 } 349 }
350 } 350 }
351 351
352 ErrorCallbackSetter callbackSetter(m_converterICU, stopOnError); 352 ErrorCallbackSetter callbackSetter(m_converterICU, stopOnError);
353 353
354 StringBuilder result; 354 StringBuilder result;
355 355
356 UChar buffer[ConversionBufferSize]; 356 UChar buffer[ConversionBufferSize];
357 UChar* bufferLimit = buffer + ConversionBufferSize; 357 UChar* bufferLimit = buffer + ConversionBufferSize;
358 const char* source = reinterpret_cast<const char*>(bytes); 358 const char* source = reinterpret_cast<const char*>(bytes);
359 const char* sourceLimit = source + length; 359 const char* sourceLimit = source + length;
360 int32_t* offsets = NULL; 360 int32_t* offsets = NULL;
361 UErrorCode err = U_ZERO_ERROR; 361 UErrorCode err = U_ZERO_ERROR;
362 362
363 do { 363 do {
364 int ucharsDecoded = decodeToBuffer(buffer, bufferLimit, source, sourceLi mit, offsets, flush, err); 364 int ucharsDecoded = decodeToBuffer(buffer, bufferLimit, source, sourceLi mit, offsets, flush != DoNotFlush, err);
365 result.append(buffer, ucharsDecoded); 365 result.append(buffer, ucharsDecoded);
366 } while (err == U_BUFFER_OVERFLOW_ERROR); 366 } while (err == U_BUFFER_OVERFLOW_ERROR);
367 367
368 if (U_FAILURE(err)) { 368 if (U_FAILURE(err)) {
369 // flush the converter so it can be reused, and not be bothered by this error. 369 // flush the converter so it can be reused, and not be bothered by this error.
370 do { 370 do {
371 decodeToBuffer(buffer, bufferLimit, source, sourceLimit, offsets, tr ue, err); 371 decodeToBuffer(buffer, bufferLimit, source, sourceLimit, offsets, tr ue, err);
372 } while (source < sourceLimit); 372 } while (source < sourceLimit);
373 sawError = true; 373 sawError = true;
374 } 374 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 { 544 {
545 return encodeCommon(characters, length, handling); 545 return encodeCommon(characters, length, handling);
546 } 546 }
547 547
548 CString TextCodecICU::encode(const LChar* characters, size_t length, Unencodable Handling handling) 548 CString TextCodecICU::encode(const LChar* characters, size_t length, Unencodable Handling handling)
549 { 549 {
550 return encodeCommon(characters, length, handling); 550 return encodeCommon(characters, length, handling);
551 } 551 }
552 552
553 } // namespace WTF 553 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/text/TextCodecICU.h ('k') | Source/wtf/text/TextCodecLatin1.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698