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

Side by Side Diff: third_party/lcms2-2.6/src/cmsnamed.c

Issue 2365663002: Fix infinite loop when calling GrowNamedColorList (Closed)
Patch Set: Created 4 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
« no previous file with comments | « third_party/lcms2-2.6/README.pdfium ('k') | no next file » | 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 // 2 //
3 // Little Color Management System 3 // Little Color Management System
4 // Copyright (c) 1998-2012 Marti Maria Saguer 4 // Copyright (c) 1998-2012 Marti Maria Saguer
5 // 5 //
6 // Permission is hereby granted, free of charge, to any person obtaining 6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the "Software"), 7 // a copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation 8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the Softwar e 10 // and/or sell copies of the Software, and to permit persons to whom the Softwar e
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID, cmsUIn t32Number n, cmsUInt32Number ColorantCount, const char* Prefix, const char* Suff ix) 507 cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID, cmsUIn t32Number n, cmsUInt32Number ColorantCount, const char* Prefix, const char* Suff ix)
508 { 508 {
509 cmsNAMEDCOLORLIST* v = (cmsNAMEDCOLORLIST*) _cmsMallocZero(ContextID, sizeof (cmsNAMEDCOLORLIST)); 509 cmsNAMEDCOLORLIST* v = (cmsNAMEDCOLORLIST*) _cmsMallocZero(ContextID, sizeof (cmsNAMEDCOLORLIST));
510 510
511 if (v == NULL) return NULL; 511 if (v == NULL) return NULL;
512 512
513 v ->List = NULL; 513 v ->List = NULL;
514 v ->nColors = 0; 514 v ->nColors = 0;
515 v ->ContextID = ContextID; 515 v ->ContextID = ContextID;
516 516
517 while (v -> Allocated < n) 517 while (v -> Allocated < n) {
518 GrowNamedColorList(v); 518 if (!GrowNamedColorList(v)) {
519 cmsFreeNamedColorList(v);
520 return NULL;
521 }
522 }
519 523
520 strncpy(v ->Prefix, Prefix, sizeof(v ->Prefix)-1); 524 strncpy(v ->Prefix, Prefix, sizeof(v ->Prefix)-1);
521 strncpy(v ->Suffix, Suffix, sizeof(v ->Suffix)-1); 525 strncpy(v ->Suffix, Suffix, sizeof(v ->Suffix)-1);
522 v->Prefix[32] = v->Suffix[32] = 0; 526 v->Prefix[32] = v->Suffix[32] = 0;
523 527
524 v -> ColorantCount = ColorantCount; 528 v -> ColorantCount = ColorantCount;
525 529
526 return v; 530 return v;
527 } 531 }
528 532
529 // Free a list 533 // Free a list
530 void CMSEXPORT cmsFreeNamedColorList(cmsNAMEDCOLORLIST* v) 534 void CMSEXPORT cmsFreeNamedColorList(cmsNAMEDCOLORLIST* v)
531 { 535 {
532 if (v == NULL) return; 536 if (v == NULL) return;
533 if (v ->List) _cmsFree(v ->ContextID, v ->List); 537 if (v ->List) _cmsFree(v ->ContextID, v ->List);
534 _cmsFree(v ->ContextID, v); 538 _cmsFree(v ->ContextID, v);
535 } 539 }
536 540
537 cmsNAMEDCOLORLIST* CMSEXPORT cmsDupNamedColorList(const cmsNAMEDCOLORLIST* v) 541 cmsNAMEDCOLORLIST* CMSEXPORT cmsDupNamedColorList(const cmsNAMEDCOLORLIST* v)
538 { 542 {
539 cmsNAMEDCOLORLIST* NewNC; 543 cmsNAMEDCOLORLIST* NewNC;
540 544
541 if (v == NULL) return NULL; 545 if (v == NULL) return NULL;
542 546
543 NewNC= cmsAllocNamedColorList(v ->ContextID, v -> nColors, v ->ColorantCount , v ->Prefix, v ->Suffix); 547 NewNC= cmsAllocNamedColorList(v ->ContextID, v -> nColors, v ->ColorantCount , v ->Prefix, v ->Suffix);
544 if (NewNC == NULL) return NULL; 548 if (NewNC == NULL) return NULL;
545 549
546 // For really large tables we need this 550 // For really large tables we need this
547 while (NewNC ->Allocated < v ->Allocated) 551 while (NewNC ->Allocated < v ->Allocated) {
548 GrowNamedColorList(NewNC); 552 if (!GrowNamedColorList(NewNC)) {
553 cmsFreeNamedColorList(NewNC);
554 return NULL;
555 }
556 }
549 557
550 memmove(NewNC ->Prefix, v ->Prefix, sizeof(v ->Prefix)); 558 memmove(NewNC ->Prefix, v ->Prefix, sizeof(v ->Prefix));
551 memmove(NewNC ->Suffix, v ->Suffix, sizeof(v ->Suffix)); 559 memmove(NewNC ->Suffix, v ->Suffix, sizeof(v ->Suffix));
552 NewNC ->ColorantCount = v ->ColorantCount; 560 NewNC ->ColorantCount = v ->ColorantCount;
553 memmove(NewNC->List, v ->List, v->nColors * sizeof(_cmsNAMEDCOLOR)); 561 memmove(NewNC->List, v ->List, v->nColors * sizeof(_cmsNAMEDCOLOR));
554 NewNC ->nColors = v ->nColors; 562 NewNC ->nColors = v ->nColors;
555 return NewNC; 563 return NewNC;
556 } 564 }
557 565
558 566
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 if (dict == NULL) return NULL; 928 if (dict == NULL) return NULL;
921 return dict ->head; 929 return dict ->head;
922 } 930 }
923 931
924 // Helper For external languages 932 // Helper For external languages
925 const cmsDICTentry* CMSEXPORT cmsDictNextEntry(const cmsDICTentry* e) 933 const cmsDICTentry* CMSEXPORT cmsDictNextEntry(const cmsDICTentry* e)
926 { 934 {
927 if (e == NULL) return NULL; 935 if (e == NULL) return NULL;
928 return e ->Next; 936 return e ->Next;
929 } 937 }
OLDNEW
« no previous file with comments | « third_party/lcms2-2.6/README.pdfium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698