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

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

Issue 2711783009: [M57] lcms upstream patches to fix security bug (Closed)
Patch Set: Created 3 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
« no previous file with comments | « third_party/lcms2-2.6/README.pdfium ('k') | third_party/lcms2-2.6/src/cmstypes.c » ('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 // 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 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 NewMPE ->Data = NULL; 1248 NewMPE ->Data = NULL;
1249 } 1249 }
1250 1250
1251 return NewMPE; 1251 return NewMPE;
1252 } 1252 }
1253 1253
1254 1254
1255 // ***************************************************************************** ****************************** 1255 // ***************************************************************************** ******************************
1256 1256
1257 // This function sets up the channel count 1257 // This function sets up the channel count
1258
1259 static 1258 static
1260 void BlessLUT(cmsPipeline* lut) 1259 cmsBool BlessLUT(cmsPipeline* lut)
1261 { 1260 {
1262 // We can set the input/ouput channels only if we have elements. 1261 // We can set the input/ouput channels only if we have elements.
1263 if (lut ->Elements != NULL) { 1262 if (lut ->Elements != NULL) {
1264 1263
1265 cmsStage *First, *Last; 1264 cmsStage* prev;
1265 cmsStage* next;
1266 cmsStage* First;
1267 cmsStage* Last;
1266 1268
1267 First = cmsPipelineGetPtrToFirstStage(lut); 1269 First = cmsPipelineGetPtrToFirstStage(lut);
1268 Last = cmsPipelineGetPtrToLastStage(lut); 1270 Last = cmsPipelineGetPtrToLastStage(lut);
1269 1271
1270 if (First != NULL)lut ->InputChannels = First ->InputChannels; 1272 if (First == NULL || Last == NULL) return FALSE;
1271 if (Last != NULL) lut ->OutputChannels = Last ->OutputChannels; 1273
1274 lut->InputChannels = First->InputChannels;
1275 lut->OutputChannels = Last->OutputChannels;
1276
1277 // Check chain consistency
1278 prev = First;
1279 next = prev->Next;
1280
1281 while (next != NULL)
1282 {
1283 if (next->InputChannels != prev->OutputChannels)
1284 return FALSE;
1285
1286 next = next->Next;
1287 prev = prev->Next;
1288 }
1272 } 1289 }
1290 return TRUE;
1273 } 1291 }
1274 1292
1275 1293
1276 // Default to evaluate the LUT on 16 bit-basis. Precision is retained. 1294 // Default to evaluate the LUT on 16 bit-basis. Precision is retained.
1277 static 1295 static
1278 void _LUTeval16(register const cmsUInt16Number In[], register cmsUInt16Number Ou t[], register const void* D) 1296 void _LUTeval16(register const cmsUInt16Number In[], register cmsUInt16Number Ou t[], register const void* D)
1279 { 1297 {
1280 cmsPipeline* lut = (cmsPipeline*) D; 1298 cmsPipeline* lut = (cmsPipeline*) D;
1281 cmsStage *mpe; 1299 cmsStage *mpe;
1282 cmsFloat32Number Storage[2][MAX_STAGE_CHANNELS] = {0.0f}; 1300 cmsFloat32Number Storage[2][MAX_STAGE_CHANNELS] = {0.0f};
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 1342
1325 1343
1326 1344
1327 1345
1328 // LUT Creation & Destruction 1346 // LUT Creation & Destruction
1329 1347
1330 cmsPipeline* CMSEXPORT cmsPipelineAlloc(cmsContext ContextID, cmsUInt32Number In putChannels, cmsUInt32Number OutputChannels) 1348 cmsPipeline* CMSEXPORT cmsPipelineAlloc(cmsContext ContextID, cmsUInt32Number In putChannels, cmsUInt32Number OutputChannels)
1331 { 1349 {
1332 cmsPipeline* NewLUT; 1350 cmsPipeline* NewLUT;
1333 1351
1352 // A value of zero in channels is allowed as placeholder
1334 if (InputChannels >= cmsMAXCHANNELS || 1353 if (InputChannels >= cmsMAXCHANNELS ||
1335 OutputChannels >= cmsMAXCHANNELS) return NULL; 1354 OutputChannels >= cmsMAXCHANNELS) return NULL;
1336 1355
1337 NewLUT = (cmsPipeline*) _cmsMallocZero(ContextID, sizeof(cmsPipeline)); 1356 NewLUT = (cmsPipeline*) _cmsMallocZero(ContextID, sizeof(cmsPipeline));
1338 if (NewLUT == NULL) return NULL; 1357 if (NewLUT == NULL) return NULL;
1339 1358
1340 1359
1341 NewLUT -> InputChannels = InputChannels; 1360 NewLUT -> InputChannels = InputChannels;
1342 NewLUT -> OutputChannels = OutputChannels; 1361 NewLUT -> OutputChannels = OutputChannels;
1343 1362
1344 NewLUT ->Eval16Fn = _LUTeval16; 1363 NewLUT ->Eval16Fn = _LUTeval16;
1345 NewLUT ->EvalFloatFn = _LUTevalFloat; 1364 NewLUT ->EvalFloatFn = _LUTevalFloat;
1346 NewLUT ->DupDataFn = NULL; 1365 NewLUT ->DupDataFn = NULL;
1347 NewLUT ->FreeDataFn = NULL; 1366 NewLUT ->FreeDataFn = NULL;
1348 NewLUT ->Data = NewLUT; 1367 NewLUT ->Data = NewLUT;
1349 NewLUT ->ContextID = ContextID; 1368 NewLUT ->ContextID = ContextID;
1350 1369
1351 BlessLUT(NewLUT); 1370 if (!BlessLUT(NewLUT))
1371 {
1372 _cmsFree(ContextID, NewLUT);
1373 return NULL;
1374 }
1352 1375
1353 return NewLUT; 1376 return NewLUT;
1354 } 1377 }
1355 1378
1356 cmsContext CMSEXPORT cmsGetPipelineContextID(const cmsPipeline* lut) 1379 cmsContext CMSEXPORT cmsGetPipelineContextID(const cmsPipeline* lut)
1357 { 1380 {
1358 _cmsAssert(lut != NULL); 1381 _cmsAssert(lut != NULL);
1359 return lut ->ContextID; 1382 return lut ->ContextID;
1360 } 1383 }
1361 1384
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 NewLUT ->EvalFloatFn = lut ->EvalFloatFn; 1470 NewLUT ->EvalFloatFn = lut ->EvalFloatFn;
1448 NewLUT ->DupDataFn = lut ->DupDataFn; 1471 NewLUT ->DupDataFn = lut ->DupDataFn;
1449 NewLUT ->FreeDataFn = lut ->FreeDataFn; 1472 NewLUT ->FreeDataFn = lut ->FreeDataFn;
1450 1473
1451 if (NewLUT ->DupDataFn != NULL) 1474 if (NewLUT ->DupDataFn != NULL)
1452 NewLUT ->Data = NewLUT ->DupDataFn(lut ->ContextID, lut->Data); 1475 NewLUT ->Data = NewLUT ->DupDataFn(lut ->ContextID, lut->Data);
1453 1476
1454 1477
1455 NewLUT ->SaveAs8Bits = lut ->SaveAs8Bits; 1478 NewLUT ->SaveAs8Bits = lut ->SaveAs8Bits;
1456 1479
1457 BlessLUT(NewLUT); 1480 if (!BlessLUT(NewLUT))
1481 {
1482 _cmsFree(lut->ContextID, NewLUT);
1483 return NULL;
1484 }
1485
1458 return NewLUT; 1486 return NewLUT;
1459 } 1487 }
1460 1488
1461 1489
1462 int CMSEXPORT cmsPipelineInsertStage(cmsPipeline* lut, cmsStageLoc loc, cmsStage * mpe) 1490 int CMSEXPORT cmsPipelineInsertStage(cmsPipeline* lut, cmsStageLoc loc, cmsStage * mpe)
1463 { 1491 {
1464 cmsStage* Anterior = NULL, *pt; 1492 cmsStage* Anterior = NULL, *pt;
1465 1493
1466 if (lut == NULL || mpe == NULL) 1494 if (lut == NULL || mpe == NULL)
1467 return FALSE; 1495 return FALSE;
(...skipping 16 matching lines...) Expand all
1484 pt = pt -> Next) Anterior = pt; 1512 pt = pt -> Next) Anterior = pt;
1485 1513
1486 Anterior ->Next = mpe; 1514 Anterior ->Next = mpe;
1487 mpe ->Next = NULL; 1515 mpe ->Next = NULL;
1488 } 1516 }
1489 break; 1517 break;
1490 default:; 1518 default:;
1491 return FALSE; 1519 return FALSE;
1492 } 1520 }
1493 1521
1494 BlessLUT(lut); 1522 return BlessLUT(lut);
1495 return TRUE;
1496 } 1523 }
1497 1524
1498 // Unlink an element and return the pointer to it 1525 // Unlink an element and return the pointer to it
1499 void CMSEXPORT cmsPipelineUnlinkStage(cmsPipeline* lut, cmsStageLoc loc, cmsStag e** mpe) 1526 void CMSEXPORT cmsPipelineUnlinkStage(cmsPipeline* lut, cmsStageLoc loc, cmsStag e** mpe)
1500 { 1527 {
1501 cmsStage *Anterior, *pt, *Last; 1528 cmsStage *Anterior, *pt, *Last;
1502 cmsStage *Unlinked = NULL; 1529 cmsStage *Unlinked = NULL;
1503 1530
1504 1531
1505 // If empty LUT, there is nothing to remove 1532 // If empty LUT, there is nothing to remove
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 lut ->Elements = NULL; 1567 lut ->Elements = NULL;
1541 break; 1568 break;
1542 default:; 1569 default:;
1543 } 1570 }
1544 1571
1545 if (mpe) 1572 if (mpe)
1546 *mpe = Unlinked; 1573 *mpe = Unlinked;
1547 else 1574 else
1548 cmsStageFree(Unlinked); 1575 cmsStageFree(Unlinked);
1549 1576
1577 // May fail, but we ignore it
1550 BlessLUT(lut); 1578 BlessLUT(lut);
1551 } 1579 }
1552 1580
1553 1581
1554 // Concatenate two LUT into a new single one 1582 // Concatenate two LUT into a new single one
1555 cmsBool CMSEXPORT cmsPipelineCat(cmsPipeline* l1, const cmsPipeline* l2) 1583 cmsBool CMSEXPORT cmsPipelineCat(cmsPipeline* l1, const cmsPipeline* l2)
1556 { 1584 {
1557 cmsStage* mpe; 1585 cmsStage* mpe;
1558 1586
1559 // If both LUTS does not have elements, we need to inherit 1587 // If both LUTS does not have elements, we need to inherit
1560 // the number of channels 1588 // the number of channels
1561 if (l1 ->Elements == NULL && l2 ->Elements == NULL) { 1589 if (l1 ->Elements == NULL && l2 ->Elements == NULL) {
1562 l1 ->InputChannels = l2 ->InputChannels; 1590 l1 ->InputChannels = l2 ->InputChannels;
1563 l1 ->OutputChannels = l2 ->OutputChannels; 1591 l1 ->OutputChannels = l2 ->OutputChannels;
1564 } 1592 }
1565 1593
1566 // Cat second 1594 // Cat second
1567 for (mpe = l2 ->Elements; 1595 for (mpe = l2 ->Elements;
1568 mpe != NULL; 1596 mpe != NULL;
1569 mpe = mpe ->Next) { 1597 mpe = mpe ->Next) {
1570 1598
1571 // We have to dup each element 1599 // We have to dup each element
1572 if (!cmsPipelineInsertStage(l1, cmsAT_END, cmsStageDup(mpe))) 1600 if (!cmsPipelineInsertStage(l1, cmsAT_END, cmsStageDup(mpe)))
1573 return FALSE; 1601 return FALSE;
1574 } 1602 }
1575 1603
1576 BlessLUT(l1); 1604 return BlessLUT(l1);
1577 return TRUE;
1578 } 1605 }
1579 1606
1580 1607
1581 cmsBool CMSEXPORT cmsPipelineSetSaveAs8bitsFlag(cmsPipeline* lut, cmsBool On) 1608 cmsBool CMSEXPORT cmsPipelineSetSaveAs8bitsFlag(cmsPipeline* lut, cmsBool On)
1582 { 1609 {
1583 cmsBool Anterior = lut ->SaveAs8Bits; 1610 cmsBool Anterior = lut ->SaveAs8Bits;
1584 1611
1585 lut ->SaveAs8Bits = On; 1612 lut ->SaveAs8Bits = On;
1586 return Anterior; 1613 return Anterior;
1587 } 1614 }
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1784 // Some clipping.... 1811 // Some clipping....
1785 for (j=0; j < 3; j++) { 1812 for (j=0; j < 3; j++) {
1786 if (x[j] < 0) x[j] = 0; 1813 if (x[j] < 0) x[j] = 0;
1787 else 1814 else
1788 if (x[j] > 1.0) x[j] = 1.0; 1815 if (x[j] > 1.0) x[j] = 1.0;
1789 } 1816 }
1790 } 1817 }
1791 1818
1792 return TRUE; 1819 return TRUE;
1793 } 1820 }
OLDNEW
« no previous file with comments | « third_party/lcms2-2.6/README.pdfium ('k') | third_party/lcms2-2.6/src/cmstypes.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698