@@ -537,6 +537,28 @@ ImageOutput::create(string_view filename, Filesystem::IOProxy* ioproxy,
537
537
format = filename;
538
538
}
539
539
540
+ ustring comma_sep_allowed_output_formats;
541
+ if (OIIO::getattribute (" allowed_output_formats" , TypeString,
542
+ &comma_sep_allowed_output_formats)) {
543
+ std::vector<std::string> allowed_output_formats;
544
+ Strutil::split (comma_sep_allowed_output_formats, allowed_output_formats,
545
+ " ," , -1 );
546
+
547
+ bool isValidFormat = 0 ;
548
+ for (std::string allowed_format : allowed_output_formats) {
549
+ if (allowed_format == format) {
550
+ isValidFormat = 1 ;
551
+ break ;
552
+ }
553
+ }
554
+
555
+ if (!isValidFormat) {
556
+ OIIO::errorfmt (
557
+ " ImageOutput::create() called: output image format not found in list of allowed formats" );
558
+ return out;
559
+ }
560
+ }
561
+
540
562
ImageOutput::Creator create_function = nullptr ;
541
563
{ // scope the lock:
542
564
std::unique_lock<std::recursive_mutex> lock (imageio_mutex);
@@ -630,6 +652,29 @@ ImageInput::create(string_view filename, bool do_open, const ImageSpec* config,
630
652
format = filename;
631
653
}
632
654
655
+ ustring comma_sep_allowed_input_formats;
656
+ if (OIIO::getattribute (" allowed_input_formats" , TypeString,
657
+ &comma_sep_allowed_input_formats)) {
658
+ std::vector<std::string> allowed_input_formats;
659
+ Strutil::split (comma_sep_allowed_input_formats, allowed_input_formats,
660
+ " ," , -1 );
661
+
662
+ bool isValidFormat = 0 ;
663
+ for (std::string allowed_format : allowed_input_formats) {
664
+ if (allowed_format == format) {
665
+ isValidFormat = 1 ;
666
+ break ;
667
+ }
668
+ }
669
+
670
+ if (!isValidFormat) {
671
+ OIIO::errorfmt (
672
+ " ImageInput::create() called: input image format not found in list of allowed formats" );
673
+ return in;
674
+ }
675
+ }
676
+
677
+
633
678
ImageInput::Creator create_function = nullptr ;
634
679
{ // scope the lock:
635
680
std::unique_lock<std::recursive_mutex> lock (imageio_mutex);
0 commit comments