Skip to content

Commit dcb38bd

Browse files
authored
api: Add global attribute imageinput:strict (#4560)
We don't do anything with this at the present time, but this PR reserves and documents this attribute for future use. The intent is to be able to set whether we want image readers to try being as tolerant as possible when reading a file with flaws (press on and see if the rest of the file is ok?), or be more conservative and abandon reading any file as soon as a corruption or invalid data is encountered (because that might be a clue that the file is arbitrarily corrupted or even maliciously constructed). I documented it as defaulting to 0 (err on the side of being permissive of bad input), with high-security applications being responsible for setting it to 1. But it's open for debate if people think that a better default is to be strict and let applications who want to be more tolerant be responsible for accepting the risk and switching the mode. Signed-off-by: Larry Gritz <[email protected]>
1 parent 34b29f3 commit dcb38bd

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/include/OpenImageIO/imageio.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,6 +2981,17 @@ OIIO_API std::string geterror(bool clear = true);
29812981
/// If nonzero, an `ImageBuf` that references a file but is not given an
29822982
/// ImageCache will read the image through the default ImageCache.
29832983
///
2984+
/// - `imageinput:strict` (int: 0)
2985+
///
2986+
/// If zero (the default), ImageInput readers will try to be very tolerant
2987+
/// of minor flaws or invalidity in image files being read, if possible just
2988+
/// skipping something erroneous it encounters in the hopes that the rest of
2989+
/// the file's data will be usable. If nonzero, anything clearly invalid in
2990+
/// the file will be understood to be a corrupt file with unreliable data at
2991+
/// best, and possibly malicious construction, and so will not attempt to
2992+
/// further decode anything in the file. This may be a better choice to
2993+
/// enable globally in an environment where security is a higher priority
2994+
/// than being tolerant of partially broken image files.
29842995
OIIO_API bool attribute(string_view name, TypeDesc type, const void* val);
29852996

29862997
/// Shortcut attribute() for setting a single integer.

src/include/imageio_pvt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ extern int limit_channels;
4747
extern int limit_imagesize_MB;
4848
extern int imagebuf_print_uncaught_errors;
4949
extern int imagebuf_use_imagecache;
50+
extern int imageinput_strict;
5051
extern atomic_ll IB_local_mem_current;
5152
extern atomic_ll IB_local_mem_peak;
5253
extern std::atomic<float> IB_total_open_time;

src/libOpenImageIO/imageio.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ int dds_bc5normal(0);
5555
int limit_channels(1024);
5656
int limit_imagesize_MB(std::min(32 * 1024,
5757
int(Sysutil::physical_memory() >> 20)));
58+
int imageinput_strict(0);
5859
ustring font_searchpath(Sysutil::getenv("OPENIMAGEIO_FONTS"));
5960
ustring plugin_searchpath(OIIO_DEFAULT_PLUGIN_SEARCHPATH);
6061
std::string format_list; // comma-separated list of all formats
@@ -403,6 +404,10 @@ attribute(string_view name, TypeDesc type, const void* val)
403404
imagebuf_use_imagecache = *(const int*)val;
404405
return true;
405406
}
407+
if (name == "imageinput:strict" && type == TypeInt) {
408+
imageinput_strict = *(const int*)val;
409+
return true;
410+
}
406411
if (name == "use_tbb" && type == TypeInt) {
407412
oiio_use_tbb = *(const int*)val;
408413
return true;
@@ -578,6 +583,10 @@ getattribute(string_view name, TypeDesc type, void* val)
578583
*(int*)val = imagebuf_use_imagecache;
579584
return true;
580585
}
586+
if (name == "imageinput:strict" && type == TypeInt) {
587+
*(int*)val = imageinput_strict;
588+
return true;
589+
}
581590
if (name == "use_tbb" && type == TypeInt) {
582591
*(int*)val = oiio_use_tbb;
583592
return true;

0 commit comments

Comments
 (0)