On 26 July 2013 21:02, Richard Hughes <hughsi...@gmail.com> wrote:
> If it fails for other people I'll work on a small
> reproducer that illustrates the problem.

Okay, reproducer attached. Simply save the profile and the C file in
the same place and do:

gcc -o test test.c `pkg-config --cflags --libs lcms2` && ./test

This is now called my "Schrödinger" bug. Basically, if you do these
exact things you can write a profile with a corrupt metadata tag:

* cmsOpenProfileFromFile() or cmsOpenProfileFromMem()
* unused = cmsReadTag(p, cmsSigMetaTag)
* cmsSaveProfileToMem()
* Save memory blob to a file

If you do cmsOpenProfileFromFile() on the new file and then
cmsReadTag(p, cmsSigMetaTag) you get:

ERROR: Bad dictionary Name/Value
ERROR: Corrupted tag 'meta'

It seems by "observing" the dictionary using cmsReadTag() somehow
corrupts it, so when it is saved it's then unreadable. If you don't do
the initial cmsReadTag(p, cmsSigMetaTag) or use cmsSaveProfileToFile()
then the bug does not manifest itself. I'm very confused, so any help
welcome, thanks!

Richard.

Attachment: ibm-t61.icc
Description: Binary data

//gcc -o test test.c `pkg-config --cflags --libs lcms2` && ./test

#include <lcms2.h>
#include <assert.h>
#include <stdlib.h>

static void
error_cb(cmsContext context_id, cmsUInt32Number code, const char *message)
{
	printf("ERROR: %s\n", message);
}

int
main(int argc, char *argv[])
{
	char *data;
	cmsHANDLE dict;
	cmsHPROFILE p;
	cmsUInt32Number clen;
	const cmsDICTentry *entry;
	FILE *fp;
	int rc;

	/* setup log handler */
	cmsSetLogErrorHandler(error_cb);

	/* open file */
	p = cmsOpenProfileFromFile("./ibm-t61.icc", "r");
	assert(p);

	/* read dictionary, but don't do anything with the value */
	//COMMENT OUT THE NEXT TWO LINES AND IT WORKS FINE!!!
	dict = cmsReadTag(p, cmsSigMetaTag);
	assert(dict);

	/* serialize profile to memory */
	rc = cmsSaveProfileToMem(p, NULL, &clen);
	assert(rc);
	data = malloc(clen);
	rc = cmsSaveProfileToMem(p, data, &clen);
	assert(rc);

	/* write the memory blob to a file */
	//NOTE: The crash does not happen if cmsSaveProfileToFile() is used */
	fp = fopen("./new.icc", "w");
	fwrite(data, 1, clen, fp);
	fclose(fp);
	free(data);

	cmsCloseProfile(p);

	/* open newly created file and read metadata */
	p = cmsOpenProfileFromFile("./new.icc", "r");
	//ERROR: Bad dictionary Name/Value
	//ERROR: Corrupted tag 'meta'
	//test: test.c:59: main: Assertion `dict' failed.
	dict = cmsReadTag(p, cmsSigMetaTag);
	assert(dict);

	return 0;
}
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Lcms-user mailing list
Lcms-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lcms-user

Reply via email to