mm2 / Little-CMS

A free, open source, CMM engine. It provides fast transforms between ICC profiles.
https://www.littlecms.com
MIT License
549 stars 174 forks source link

optimize the code in cmsFreeProfileSequenceDescription() #406

Closed x2018 closed 11 months ago

x2018 commented 11 months ago

Hi, when I test the release version 2.15, I got the error below:

==12022==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000028 (pc 0x0000006a3e15 bp 0x7ffff47d3380 sp 0x7ffff47d32c0 T0)
==12022==The signal is caused by a READ memory access.
==12022==Hint: address points to the zero page.
    #0 0x6a3e15 in cmsFreeProfileSequenceDescription Little-CMS-lcms2.15/src/cmsnamed.c:818:40
    #1 0x6a4d99 in cmsDupProfileSequenceDescription Little-CMS-lcms2.15/src/cmsnamed.c:864:5

Based on simple analysis, it is because pseq ->seq is not checked in cmsFreeProfileSequenceDescription() of version 2.15. I found that the above problem is fixed in https://github.com/mm2/Little-CMS/commit/ac9e8e16e6f19735b95e6f0e13940256c99aeecd, but the code could still be optimized: if pseq ->seq is NULL, then it is unnecessary to enter the loop so that we just need to check the pointer one time.