Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/png.imageio/png_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,30 @@ put_parameter(png_structp& sp, png_infop& ip, const std::string& _name,
return true;
}
#endif

// Before handling general named metadata, suppress format-specific
// metadata hints meant for other formats that are not meant to be literal
// metadata written to the file. This includes anything with a namespace
// prefix of "oiio:" or the name of any other file format.
auto colonpos = name.find(':');
if (colonpos != std::string::npos) {
std::string prefix = Strutil::lower(name.substr(0, colonpos));
if (prefix != "png" && is_imageio_format_name(prefix))
return false;
if (prefix == "oiio")
return false;
}

if (type == TypeDesc::STRING) {
// We can save arbitrary string metadata in multiple png text entries.
// Is that ok? Should we also do it for other types by converting to
// string?
png_text t;
t.compression = PNG_TEXT_COMPRESSION_NONE;
t.key = (char*)ustring(name).c_str();
t.text = *(char**)data; // Already uniquified
text.push_back(t);
return true;
}

return false;
Expand Down
8 changes: 4 additions & 4 deletions testsuite/png-damaged/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ iconvert ERROR copying "../oiio-images/png/broken/invalid_gray_alpha_sbit.png" t
PNG read error: IDAT: Read error: hit end of file in png reader
libpng error: No IDATs written into file
Comparing "../oiio-images/png/broken/invalid_gray_alpha_sbit.png" and "invalid_gray_alpha_sbit.png"
libpng error: tEXt: Read error: hit end of file in png reader
libpng error: tEXt: Read error: hit end of file in png reader
libpng error: oFFs: Read error: hit end of file in png reader
libpng error: oFFs: Read error: hit end of file in png reader
idiff ERROR: Could not read invalid_gray_alpha_sbit.png:
Invalid image file "invalid_gray_alpha_sbit.png": Read error: hit end of file in png reader
PNG read error: tEXt: Read error: hit end of file in png reader
PNG read error: oFFs: Read error: hit end of file in png reader
Invalid image file "invalid_gray_alpha_sbit.png": Read error: hit end of file in png reader
PNG read error: tEXt: Read error: hit end of file in png reader
PNG read error: oFFs: Read error: hit end of file in png reader
Loading