r21679 by jghali - #14494: detect incorrect icc profiles embedded in broken JPEGs files

scribus-commit scribus-commit at lists.scribus.net
Sun Dec 25 23:43:50 UTC 2016


Author: jghali
Date: Sun Dec 25 23:43:50 2016
New Revision: 21679

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21679
Log:
#14494: detect incorrect icc profiles embedded in broken JPEGs files

Modified:
    trunk/Scribus/scribus/imagedataloaders/scimgdataloader_jpeg.cpp

Modified: trunk/Scribus/scribus/imagedataloaders/scimgdataloader_jpeg.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21679&path=/trunk/Scribus/scribus/imagedataloaders/scimgdataloader_jpeg.cpp
==============================================================================
--- trunk/Scribus/scribus/imagedataloaders/scimgdataloader_jpeg.cpp	(original)
+++ trunk/Scribus/scribus/imagedataloaders/scimgdataloader_jpeg.cpp	Sun Dec 25 23:43:50 2016
@@ -81,9 +81,20 @@
 	unsigned char* EmbedBuffer = 0;
 	if (read_jpeg_marker(ICC_MARKER, &cinfo, &EmbedBuffer, &EmbedLen))
 	{
+		bool profileIsValid = false;
 		QByteArray profArray = QByteArray((const char*) EmbedBuffer, EmbedLen);
 		ScColorProfile prof = ScCore->defaultEngine.openProfileFromMem(profArray);
 		if (prof)
+		{
+			eColorSpaceType colorSpace = prof.colorSpace();
+			if (colorSpace == ColorSpace_Rgb)
+				profileIsValid = (cinfo.output_components == 3);
+			if (colorSpace == ColorSpace_Cmyk)
+				profileIsValid = (cinfo.output_components == 4);
+			if (colorSpace == ColorSpace_Gray)
+				profileIsValid = (cinfo.output_components == 1);
+		}
+		if (profileIsValid)
 		{
 			if (prof.colorSpace() == ColorSpace_Rgb)
 				m_profileComponents = 3;
@@ -227,22 +238,6 @@
 	else
 		m_imageInfoRecord.exifDataValid = false;
 	m_imageInfoRecord.exifInfo.thumbnail = QImage();
-	unsigned int EmbedLen = 0;
-	unsigned char* EmbedBuffer;
-	if (read_jpeg_marker(ICC_MARKER, &cinfo, &EmbedBuffer, &EmbedLen))
-	{
-		QByteArray profArray((const char*) EmbedBuffer, EmbedLen);
-		ScColorProfile prof = ScCore->defaultEngine.openProfileFromMem(profArray);
-		m_embeddedProfile = profArray;
-		m_imageInfoRecord.profileName = prof.productDescription();
-		m_imageInfoRecord.isEmbedded  = true;
-		free(EmbedBuffer);
-	}
-	else
-	{
-		m_imageInfoRecord.isEmbedded = false;
-		m_imageInfoRecord.profileName = "";
-	}
 
 	if (cinfo.density_unit == 0)
 	{
@@ -286,6 +281,40 @@
 	else if (cinfo.output_components == 1)
 		m_imageInfoRecord.colorspace = ColorSpaceGray;
 	m_imageInfoRecord.progressive = jpeg_has_multiple_scans(&cinfo);
+
+	unsigned int EmbedLen = 0;
+	unsigned char* EmbedBuffer;
+	if (read_jpeg_marker(ICC_MARKER, &cinfo, &EmbedBuffer, &EmbedLen))
+	{
+		bool profileIsValid = false;
+		QByteArray profArray((const char*) EmbedBuffer, EmbedLen);
+		ScColorProfile prof = ScCore->defaultEngine.openProfileFromMem(profArray);
+		if (prof)
+		{
+			// #14494: some tools out there produce broken JPEGs with inconsistent
+			// profile and image colorspaces. Check consistency, and if profile  
+			// and image data are not consistent, discard embedded profile.
+			eColorSpaceType colorSpace = prof.colorSpace();
+			if (colorSpace == ColorSpace_Rgb)
+				profileIsValid = (cinfo.output_components == 3);
+			if (colorSpace == ColorSpace_Cmyk)
+				profileIsValid = (cinfo.output_components == 4);
+			if (colorSpace == ColorSpace_Gray)
+				profileIsValid = (cinfo.output_components == 1);
+		}
+		if (profileIsValid)
+		{
+			m_embeddedProfile = profArray;
+			m_imageInfoRecord.profileName = prof.productDescription();
+		}
+		m_imageInfoRecord.isEmbedded = profileIsValid;
+		free(EmbedBuffer);
+	}
+	else
+	{
+		m_imageInfoRecord.isEmbedded = false;
+		m_imageInfoRecord.profileName = "";
+	}
 
 	unsigned int PhotoshopLen = 0;
 	unsigned char * PhotoshopBuffer = 0;




More information about the scribus-commit mailing list