Skip to content

Commit c8bc71f

Browse files
committed
fix(png): We were not correctly suppressing hint metadata (#4983)
Each file writer that is capable of writing arbitrary metadata is supposed to tace care to suppress hints meant for other writers, or for OIIO in general, not interpret them as literal metadata to write to the file. PNG was not doing so, and ended up writing hints as literal metadata. This brings it in line with our behavior when writing OpenEXR and other formats. --------- Signed-off-by: Larry Gritz <[email protected]>
1 parent 3a0ce0c commit c8bc71f

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/png.imageio/png_pvt.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,30 @@ put_parameter(png_structp& sp, png_infop& ip, const std::string& _name,
564564
return true;
565565
}
566566
#endif
567+
568+
// Before handling general named metadata, suppress format-specific
569+
// metadata hints meant for other formats that are not meant to be literal
570+
// metadata written to the file. This includes anything with a namespace
571+
// prefix of "oiio:" or the name of any other file format.
572+
auto colonpos = name.find(':');
573+
if (colonpos != std::string::npos) {
574+
std::string prefix = Strutil::lower(name.substr(0, colonpos));
575+
if (prefix != "png" && is_imageio_format_name(prefix))
576+
return false;
577+
if (prefix == "oiio")
578+
return false;
579+
}
580+
567581
if (type == TypeDesc::STRING) {
582+
// We can save arbitrary string metadata in multiple png text entries.
583+
// Is that ok? Should we also do it for other types by converting to
584+
// string?
568585
png_text t;
569586
t.compression = PNG_TEXT_COMPRESSION_NONE;
570587
t.key = (char*)ustring(name).c_str();
571588
t.text = *(char**)data; // Already uniquified
572589
text.push_back(t);
590+
return true;
573591
}
574592

575593
return false;

testsuite/png-damaged/ref/out.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ iconvert ERROR copying "../oiio-images/png/broken/invalid_gray_alpha_sbit.png" t
44
PNG read error: IDAT: Read error: hit end of file in png reader
55
libpng error: No IDATs written into file
66
Comparing "../oiio-images/png/broken/invalid_gray_alpha_sbit.png" and "invalid_gray_alpha_sbit.png"
7-
libpng error: tEXt: Read error: hit end of file in png reader
8-
libpng error: tEXt: Read error: hit end of file in png reader
7+
libpng error: oFFs: Read error: hit end of file in png reader
8+
libpng error: oFFs: Read error: hit end of file in png reader
99
idiff ERROR: Could not read invalid_gray_alpha_sbit.png:
1010
Invalid image file "invalid_gray_alpha_sbit.png": Read error: hit end of file in png reader
11-
PNG read error: tEXt: Read error: hit end of file in png reader
11+
PNG read error: oFFs: Read error: hit end of file in png reader
1212
Invalid image file "invalid_gray_alpha_sbit.png": Read error: hit end of file in png reader
13-
PNG read error: tEXt: Read error: hit end of file in png reader
13+
PNG read error: oFFs: Read error: hit end of file in png reader

0 commit comments

Comments
 (0)