Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 94bec17

Browse files
authoredJan 22, 2019
Merge pull request #5 from SDWebImage/bugfix_iccp_leak
Fix the potential leak of chunk iterator used for ICC Profile colorSpace check
2 parents 18c620a + 3e0e45d commit 94bec17

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed
 

‎SDWebImageWebPCoder/Classes/SDImageWebPCoder.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,17 @@ - (nonnull CGColorSpaceRef)sd_colorSpaceWithDemuxer:(nonnull WebPDemuxer *)demux
422422
// WebP contains ICC Profile should use the desired colorspace, instead of default device colorspace
423423
// See: https://developers.google.com/speed/webp/docs/riff_container#color_profile
424424

425-
WebPChunkIterator chunk_iter;
426425
CGColorSpaceRef colorSpaceRef = NULL;
426+
uint32_t flags = WebPDemuxGetI(demuxer, WEBP_FF_FORMAT_FLAGS);
427427

428-
int result = WebPDemuxGetChunk(demuxer, "ICCP", 1, &chunk_iter);
429-
if (result) {
430-
NSData *profileData = [NSData dataWithBytes:chunk_iter.chunk.bytes length:chunk_iter.chunk.size];
431-
colorSpaceRef = CGColorSpaceCreateWithICCProfile((__bridge CFDataRef)profileData);
428+
if (flags & ICCP_FLAG) {
429+
WebPChunkIterator chunk_iter;
430+
int result = WebPDemuxGetChunk(demuxer, "ICCP", 1, &chunk_iter);
431+
if (result) {
432+
NSData *profileData = [NSData dataWithBytesNoCopy:(void *)chunk_iter.chunk.bytes length:chunk_iter.chunk.size freeWhenDone:NO];
433+
colorSpaceRef = CGColorSpaceCreateWithICCProfile((__bridge CFDataRef)profileData);
434+
WebPDemuxReleaseChunkIterator(&chunk_iter);
435+
}
432436
}
433437

434438
if (!colorSpaceRef) {

0 commit comments

Comments
 (0)
Please sign in to comment.