Skip to content

Commit

Permalink
OpenImageIOAlgo : Properly handle empty metadata values
Browse files Browse the repository at this point in the history
`ustring->c_str()` returns a `NULL` 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.

The solution here is to use `string()` instead of `c_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 internal
`ustring` table:
https://github.com/AcademySoftwareFoundation/OpenImageIO/blob/master/src/include/OpenImageIO/ustring.h#L760
  • Loading branch information
ivanimanishi committed Nov 16, 2023
1 parent a2935e3 commit 5262454
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
10.5.x.x (relative to 10.5.4.0)
========

Fixes
-----

- OpenImageIOAlgo : Properly handle empty metadata values

10.5.4.0 (relative to 10.5.3.0)
========
Expand Down
2 changes: 1 addition & 1 deletion src/IECoreImage/OpenImageIOAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
{
if ( type.arraylen == 0 )
{
return new StringData( static_cast<const ustring *>( value.data() )->c_str() );
return new StringData( static_cast<const ustring *>( value.data() )->string() );
}
else
{
Expand Down

0 comments on commit 5262454

Please sign in to comment.