OpenImageIOAlgo : Properly handle empty metadata values #1396
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ustring::c_str()
returns aNULL
pointer for empty strings.https://github.com/AcademySoftwareFoundation/OpenImageIO/blob/master/src/include/OpenImageIO/ustring.h#L139-L143 https://github.com/AcademySoftwareFoundation/OpenImageIO/blob/master/src/include/OpenImageIO/ustring.h#L290
This error was noticed when other OIIO changes started returning new metadata keys for which the values were empty strings, and thus causing segfaults when the
NULL
pointer wasn't handled properly (RuntimeError: basic_string::_S_construct null not valid
).The solution here is to use
string()
instead ofc_str()
, which returns an empty string in those cases, and is expected to be equally performant since the std strings are already stored in the internalustring
table:https://github.com/AcademySoftwareFoundation/OpenImageIO/blob/master/src/include/OpenImageIO/ustring.h#L760
The image that was causing the errors is a large one and I couldn't easily create an alternative one to include as a
unittest
.For reference though, the image being read was a
tiff
and the offending metadata key wasICCProfile:platform_signature
.Also, there are other references to
ustring::c_str()
in this file. Those however are likely expecting basic c-string pointers, so I didn't change them. @johnhaddon, if you think that any of those would also cause issues if they got aNULL
pointer back, we probably want to address them too, likely by checking for theNULL
value specifically and handling that differently.Checklist