Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: Add global attribute imageinput:strict #4560

Merged
merged 1 commit into from
Dec 19, 2024
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
11 changes: 11 additions & 0 deletions src/include/OpenImageIO/imageio.h
Original file line number Diff line number Diff line change
Expand Up @@ -2981,6 +2981,17 @@ OIIO_API std::string geterror(bool clear = true);
/// If nonzero, an `ImageBuf` that references a file but is not given an
/// ImageCache will read the image through the default ImageCache.
///
/// - `imageinput:strict` (int: 0)
///
/// If zero (the default), ImageInput readers will try to be very tolerant
/// of minor flaws or invalidity in image files being read, if possible just
/// skipping something erroneous it encounters in the hopes that the rest of
/// the file's data will be usable. If nonzero, anything clearly invalid in
/// the file will be understood to be a corrupt file with unreliable data at
/// best, and possibly malicious construction, and so will not attempt to
/// further decode anything in the file. This may be a better choice to
/// enable globally in an environment where security is a higher priority
/// than being tolerant of partially broken image files.
OIIO_API bool attribute(string_view name, TypeDesc type, const void* val);

/// Shortcut attribute() for setting a single integer.
Expand Down
1 change: 1 addition & 0 deletions src/include/imageio_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extern int limit_channels;
extern int limit_imagesize_MB;
extern int imagebuf_print_uncaught_errors;
extern int imagebuf_use_imagecache;
extern int imageinput_strict;
extern atomic_ll IB_local_mem_current;
extern atomic_ll IB_local_mem_peak;
extern std::atomic<float> IB_total_open_time;
Expand Down
9 changes: 9 additions & 0 deletions src/libOpenImageIO/imageio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ int dds_bc5normal(0);
int limit_channels(1024);
int limit_imagesize_MB(std::min(32 * 1024,
int(Sysutil::physical_memory() >> 20)));
int imageinput_strict(0);
ustring font_searchpath(Sysutil::getenv("OPENIMAGEIO_FONTS"));
ustring plugin_searchpath(OIIO_DEFAULT_PLUGIN_SEARCHPATH);
std::string format_list; // comma-separated list of all formats
Expand Down Expand Up @@ -403,6 +404,10 @@ attribute(string_view name, TypeDesc type, const void* val)
imagebuf_use_imagecache = *(const int*)val;
return true;
}
if (name == "imageinput:strict" && type == TypeInt) {
imageinput_strict = *(const int*)val;
return true;
}
if (name == "use_tbb" && type == TypeInt) {
oiio_use_tbb = *(const int*)val;
return true;
Expand Down Expand Up @@ -578,6 +583,10 @@ getattribute(string_view name, TypeDesc type, void* val)
*(int*)val = imagebuf_use_imagecache;
return true;
}
if (name == "imageinput:strict" && type == TypeInt) {
*(int*)val = imageinput_strict;
return true;
}
if (name == "use_tbb" && type == TypeInt) {
*(int*)val = oiio_use_tbb;
return true;
Expand Down
Loading