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

Side by Side Diff: src/ports/SkFontConfigParser_android.cpp

Issue 925933003: Verify all parsed test font files start with cap. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comment. Created 5 years, 10 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
« no previous file with comments | « no previous file | tests/FontConfigParser.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 2011 The Android Open Source Project 2 * Copyright 2011 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkFontConfigParser_android.h" 8 #include "SkFontConfigParser_android.h"
9 #include "SkFontMgr_android.h" 9 #include "SkFontMgr_android.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 442
443 // Disable entity processing, to inhibit internal entity expansion. See expa t CVE-2013-0340 443 // Disable entity processing, to inhibit internal entity expansion. See expa t CVE-2013-0340
444 XML_SetEntityDeclHandler(parser, xml_entity_decl_handler); 444 XML_SetEntityDeclHandler(parser, xml_entity_decl_handler);
445 445
446 // Start parsing oldschool; switch these in flight if we detect a newer vers ion of the file. 446 // Start parsing oldschool; switch these in flight if we detect a newer vers ion of the file.
447 XML_SetElementHandler(parser, jbParser::start_element_handler, jbParser::end _element_handler); 447 XML_SetElementHandler(parser, jbParser::start_element_handler, jbParser::end _element_handler);
448 448
449 // One would assume it would be faster to have a buffer on the stack and cal l XML_Parse. 449 // One would assume it would be faster to have a buffer on the stack and cal l XML_Parse.
450 // But XML_Parse will call XML_GetBuffer anyway and memmove the passed buffe r into it. 450 // But XML_Parse will call XML_GetBuffer anyway and memmove the passed buffe r into it.
451 // (Unless XML_CONTEXT_BYTES is undefined, but all users define it.) 451 // (Unless XML_CONTEXT_BYTES is undefined, but all users define it.)
452 static const int bufferSize = 512; 452 // In debug, buffer a small odd number of bytes to detect slicing in XML_Cha racterDataHandler.
453 static const int bufferSize = 512 SkDEBUGCODE( - 507);
453 bool done = false; 454 bool done = false;
454 while (!done) { 455 while (!done) {
455 void* buffer = XML_GetBuffer(parser, bufferSize); 456 void* buffer = XML_GetBuffer(parser, bufferSize);
456 if (!buffer) { 457 if (!buffer) {
457 SkDebugf("Could not buffer enough to continue.\n"); 458 SkDebugf("Could not buffer enough to continue.\n");
458 return -1; 459 return -1;
459 } 460 }
460 size_t len = file.read(buffer, bufferSize); 461 size_t len = file.read(buffer, bufferSize);
461 done = file.isAtEnd(); 462 done = file.isAtEnd();
462 XML_Status status = XML_ParseBuffer(parser, len, done); 463 XML_Status status = XML_ParseBuffer(parser, len, done);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // The framework is beyond Android 4.2 and can therefore skip this function 502 // The framework is beyond Android 4.2 and can therefore skip this function
502 return; 503 return;
503 #endif 504 #endif
504 505
505 SkAutoTCallIProc<DIR, closedir> fontDirectory(opendir(dir)); 506 SkAutoTCallIProc<DIR, closedir> fontDirectory(opendir(dir));
506 if (NULL == fontDirectory) { 507 if (NULL == fontDirectory) {
507 return; 508 return;
508 } 509 }
509 510
510 for (struct dirent* dirEntry; (dirEntry = readdir(fontDirectory));) { 511 for (struct dirent* dirEntry; (dirEntry = readdir(fontDirectory));) {
511 // The size of both the prefix, suffix, and a minimum valid language cod e 512 // The size of the prefix and suffix.
512 static const size_t minSize = sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1 513 static const size_t fixedLen = sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1
513 + sizeof(LOCALE_FALLBACK_FONTS_SUFFIX) - 1 514 + sizeof(LOCALE_FALLBACK_FONTS_SUFFIX) - 1;
514 + 2; 515
516 // The size of the prefix, suffix, and a minimum valid language code
517 static const size_t minSize = fixedLen + 2;
515 518
516 SkString fileName(dirEntry->d_name); 519 SkString fileName(dirEntry->d_name);
517 if (fileName.size() < minSize || 520 if (fileName.size() < minSize ||
518 !fileName.startsWith(LOCALE_FALLBACK_FONTS_PREFIX) || 521 !fileName.startsWith(LOCALE_FALLBACK_FONTS_PREFIX) ||
519 !fileName.endsWith(LOCALE_FALLBACK_FONTS_SUFFIX)) 522 !fileName.endsWith(LOCALE_FALLBACK_FONTS_SUFFIX))
520 { 523 {
521 continue; 524 continue;
522 } 525 }
523 526
524 static const size_t fixedLen = sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1
525 + sizeof(LOCALE_FALLBACK_FONTS_SUFFIX) - 1;
526
527 SkString locale(fileName.c_str() + sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1, 527 SkString locale(fileName.c_str() + sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1,
528 fileName.size() - fixedLen); 528 fileName.size() - fixedLen);
529 529
530 SkString absoluteFilename; 530 SkString absoluteFilename;
531 absoluteFilename.printf("%s/%s", dir, fileName.c_str()); 531 absoluteFilename.printf("%s/%s", dir, fileName.c_str());
532 532
533 SkTDArray<FontFamily*> langSpecificFonts; 533 SkTDArray<FontFamily*> langSpecificFonts;
534 parse_config_file(absoluteFilename.c_str(), langSpecificFonts, basePath, true); 534 parse_config_file(absoluteFilename.c_str(), langSpecificFonts, basePath, true);
535 535
536 for (int i = 0; i < langSpecificFonts.count(); ++i) { 536 for (int i = 0; i < langSpecificFonts.count(); ++i) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 const char* tag = fTag.c_str(); 623 const char* tag = fTag.c_str();
624 624
625 // strip off the rightmost "-.*" 625 // strip off the rightmost "-.*"
626 const char* parentTagEnd = strrchr(tag, '-'); 626 const char* parentTagEnd = strrchr(tag, '-');
627 if (parentTagEnd == NULL) { 627 if (parentTagEnd == NULL) {
628 return SkLanguage(); 628 return SkLanguage();
629 } 629 }
630 size_t parentTagLen = parentTagEnd - tag; 630 size_t parentTagLen = parentTagEnd - tag;
631 return SkLanguage(tag, parentTagLen); 631 return SkLanguage(tag, parentTagLen);
632 } 632 }
OLDNEW
« no previous file with comments | « no previous file | tests/FontConfigParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698