Skip to content

Commit e11125d

Browse files
authored
Merge pull request #1704 from AcademySoftwareFoundation/v11_0_0_vdb_fixes
Bug fixes to v11.0.0
2 parents 49dc158 + 1d6f632 commit e11125d

File tree

7 files changed

+77
-38
lines changed

7 files changed

+77
-38
lines changed

cmake/FindOpenVDB.cmake

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,37 @@ endif()
491491
# Add standard dependencies
492492

493493
find_package(TBB REQUIRED COMPONENTS tbb)
494+
find_package(Boost REQUIRED COMPONENTS iostreams)
494495

495496
# Add deps for pyopenvdb
497+
# @todo track for numpy
496498

497499
if(pyopenvdb IN_LIST OpenVDB_FIND_COMPONENTS)
498500
find_package(Python REQUIRED)
501+
502+
# Boost python handling - try and find both python and pythonXx (version suffixed).
503+
# Prioritize the version suffixed library, failing if neither exist.
504+
505+
find_package(Boost ${MINIMUM_BOOST_VERSION}
506+
QUIET COMPONENTS python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}
507+
)
508+
509+
if(TARGET Boost::python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR})
510+
set(BOOST_PYTHON_LIB "python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")
511+
message(STATUS "Found boost_python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")
512+
else()
513+
find_package(Boost ${MINIMUM_BOOST_VERSION} QUIET COMPONENTS python)
514+
if(TARGET Boost::python)
515+
set(BOOST_PYTHON_LIB "python")
516+
message(STATUS "Found non-suffixed boost_python, assuming to be python version "
517+
"\"${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}\" compatible"
518+
)
519+
else()
520+
message(FATAL_ERROR "Unable to find boost_python or "
521+
"boost_python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}."
522+
)
523+
endif()
524+
endif()
499525
endif()
500526

501527
# Add deps for openvdb_ax
@@ -630,10 +656,6 @@ if(OpenVDB_USES_IMATH_HALF)
630656
find_package(Imath REQUIRED CONFIG)
631657
endif()
632658

633-
if(OpenVDB_USES_DELAYED_LOADING)
634-
find_package(Boost REQUIRED COMPONENTS iostreams)
635-
endif()
636-
637659
if(UNIX)
638660
find_package(Threads REQUIRED)
639661
endif()
@@ -744,7 +766,7 @@ if(OpenVDB_pyopenvdb_LIBRARY)
744766
set_target_properties(OpenVDB::pyopenvdb PROPERTIES
745767
IMPORTED_LOCATION "${OpenVDB_pyopenvdb_LIBRARY}"
746768
INTERFACE_INCLUDE_DIRECTORIES "${OpenVDB_pyopenvdb_INCLUDE_DIR};${PYTHON_INCLUDE_DIR}"
747-
INTERFACE_LINK_LIBRARIES "OpenVDB::openvdb;${PYTHON_LIBRARIES}"
769+
INTERFACE_LINK_LIBRARIES "OpenVDB::openvdb;Boost::${BOOST_PYTHON_LIB};${PYTHON_LIBRARIES}"
748770
INTERFACE_COMPILE_FEATURES cxx_std_17
749771
)
750772
endif()

doc/build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ PyBind11 | C++/python bindings
267267
NumPy | Scientific computing with Python | Optional (Python) |
268268
LLVM | Target-independent code generation | OpenVDB AX |
269269

270-
At a minimum a matching C++17 compiler and CMake will be required. See
270+
At a minimum, boost, a matching C++17 compiler and CMake will be required. See
271271
the full [dependency list](@ref dependencies) for help with downloading and
272272
installing the above software. Note that as Blosc and ZLib are provided as part
273273
of the Houdini installation `USE_BLOSC` and `USE_ZLIB` should be left `ON`.

doc/dependencies.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Reference Platform, but for those that do, their specified versions are
3636

3737
Component | Requirements | Optional
3838
----------------------- | ----------------------------------------------- | --------
39-
OpenVDB Core Library | CMake, C++17 compiler, TBB::tbb | Blosc, ZLib, Log4cplus, Imath::Imath, Boost::iostream
39+
OpenVDB Core Library | CMake, C++17 compiler, TBB::tbb, Boost::headers | Blosc, ZLib, Log4cplus, Imath::Imath, Boost::iostream
4040
OpenVDB Print | Core Library dependencies | -
4141
OpenVDB LOD | Core Library dependencies | -
4242
OpenVDB Render | Core Library dependencies | OpenEXR, Imath::Imath, libpng
@@ -65,7 +65,7 @@ Imath | 3.1 | Latest | Half precision floating points
6565
OpenEXR | 3.1 | Latest | EXR serialization support | Y | Y | http://www.openexr.com
6666
TBB | 2020.2 | 2020.3 | Threading Building Blocks - template library for task parallelism | Y | Y | https://www.threadingbuildingblocks.org
6767
ZLIB | 1.2.7 | Latest | Compression library for disk serialization compression | Y | Y | https://www.zlib.net
68-
Boost | 1.73 | 1.80 | Components: iostreams | Y | Y | https://www.boost.org
68+
Boost | 1.73 | 1.80 | Components: headers, iostreams | Y | Y | https://www.boost.org
6969
LLVM | 10.0.0 | 13.0.0* | Target-independent code generation | Y | Y | https://llvm.org/
7070
Bison | 3.0.0 | 3.7.0 | General-purpose parser generator | Y | Y | https://www.gnu.org/software/gcc
7171
Flex | 2.6.0 | 2.6.4 | Fast lexical analyzer generator | Y | Y | https://github.com/westes/flex

openvdb/openvdb/CMakeLists.txt

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,16 @@ endif()
110110

111111
if(OPENVDB_USE_DELAYED_LOADING)
112112
find_package(Boost ${MINIMUM_BOOST_VERSION} REQUIRED COMPONENTS iostreams)
113+
else()
114+
find_package(Boost ${MINIMUM_BOOST_VERSION} REQUIRED COMPONENTS headers)
115+
endif()
113116

114-
if(OPENVDB_FUTURE_DEPRECATION AND FUTURE_MINIMUM_BOOST_VERSION)
115-
# The X.Y.Z boost version value isn't available until CMake 3.14
116-
set(FULL_BOOST_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
117-
if(${FULL_BOOST_VERSION} VERSION_LESS FUTURE_MINIMUM_BOOST_VERSION)
118-
message(DEPRECATION "Support for Boost versions < ${FUTURE_MINIMUM_BOOST_VERSION} "
119-
"is deprecated and will be removed.")
120-
endif()
117+
if(OPENVDB_FUTURE_DEPRECATION AND FUTURE_MINIMUM_BOOST_VERSION)
118+
# The X.Y.Z boost version value isn't available until CMake 3.14
119+
set(FULL_BOOST_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
120+
if(${FULL_BOOST_VERSION} VERSION_LESS FUTURE_MINIMUM_BOOST_VERSION)
121+
message(DEPRECATION "Support for Boost versions < ${FUTURE_MINIMUM_BOOST_VERSION} "
122+
"is deprecated and will be removed.")
121123
endif()
122124
endif()
123125

@@ -244,17 +246,20 @@ endif()
244246

245247
if(OPENVDB_USE_DELAYED_LOADING)
246248
list(APPEND OPENVDB_CORE_DEPENDENT_LIBS Boost::iostreams)
247-
if(WIN32)
248-
# Boost headers contain #pragma commands on Windows which causes Boost
249-
# libraries to be linked in automatically. Custom boost installations
250-
# may find that these naming conventions don't always match and can
251-
# cause linker errors. This option disables this feature of Boost. Note
252-
# -DBOOST_ALL_NO_LIB can also be provided manually.
253-
if(OPENVDB_DISABLE_BOOST_IMPLICIT_LINKING)
254-
list(APPEND OPENVDB_CORE_DEPENDENT_LIBS
255-
Boost::disable_autolinking # add -DBOOST_ALL_NO_LIB
256-
)
257-
endif()
249+
else()
250+
list(APPEND OPENVDB_CORE_DEPENDENT_LIBS Boost::headers)
251+
endif()
252+
253+
if(WIN32)
254+
# Boost headers contain #pragma commands on Windows which causes Boost
255+
# libraries to be linked in automatically. Custom boost installations
256+
# may find that these naming conventions don't always match and can
257+
# cause linker errors. This option disables this feature of Boost. Note
258+
# -DBOOST_ALL_NO_LIB can also be provided manually.
259+
if(OPENVDB_DISABLE_BOOST_IMPLICIT_LINKING)
260+
list(APPEND OPENVDB_CORE_DEPENDENT_LIBS
261+
Boost::disable_autolinking # add -DBOOST_ALL_NO_LIB
262+
)
258263
endif()
259264
endif()
260265

openvdb/openvdb/io/Compression.cc

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,23 @@ unzipFromStream(std::istream& is, char* data, size_t numBytes)
123123
{
124124
// Read the size of the compressed data.
125125
// A negative size indicates uncompressed data.
126-
Int64 numZippedBytes;
126+
Int64 numZippedBytes{0};
127127
is.read(reinterpret_cast<char*>(&numZippedBytes), 8);
128+
if (!is.good())
129+
OPENVDB_THROW(RuntimeError, "Stream failure reading the size of a zip chunk");
128130

129131
if (numZippedBytes <= 0) {
132+
// Check for an error
133+
if (size_t(-numZippedBytes) != numBytes) {
134+
OPENVDB_THROW(RuntimeError, "Expected to read a " << numBytes
135+
<< "-byte chunk, got a " << -numZippedBytes << "-byte chunk");
136+
}
130137
// Read the uncompressed data.
131138
if (data == nullptr) {
132139
is.seekg(-numZippedBytes, std::ios_base::cur);
133140
} else {
134141
is.read(data, -numZippedBytes);
135142
}
136-
if (size_t(-numZippedBytes) != numBytes) {
137-
OPENVDB_THROW(RuntimeError, "Expected to read a " << numBytes
138-
<< "-byte chunk, got a " << -numZippedBytes << "-byte chunk");
139-
}
140143
} else {
141144
if (data == nullptr) {
142145
// Seek over the compressed data.
@@ -268,20 +271,24 @@ bloscFromStream(std::istream& is, char* data, size_t numBytes)
268271
{
269272
// Read the size of the compressed data.
270273
// A negative size indicates uncompressed data.
271-
Int64 numCompressedBytes;
274+
Int64 numCompressedBytes{0};
272275
is.read(reinterpret_cast<char*>(&numCompressedBytes), 8);
273276

277+
if (!is.good())
278+
OPENVDB_THROW(RuntimeError, "Stream failure reading the size of a blosc chunk");
279+
274280
if (numCompressedBytes <= 0) {
281+
// Check for an error
282+
if (size_t(-numCompressedBytes) != numBytes) {
283+
OPENVDB_THROW(RuntimeError, "Expected to read a " << numBytes
284+
<< "-byte uncompressed chunk, got a " << -numCompressedBytes << "-byte chunk");
285+
}
275286
// Read the uncompressed data.
276287
if (data == nullptr) {
277288
is.seekg(-numCompressedBytes, std::ios_base::cur);
278289
} else {
279290
is.read(data, -numCompressedBytes);
280291
}
281-
if (size_t(-numCompressedBytes) != numBytes) {
282-
OPENVDB_THROW(RuntimeError, "Expected to read a " << numBytes
283-
<< "-byte uncompressed chunk, got a " << -numCompressedBytes << "-byte chunk");
284-
}
285292
} else {
286293
if (data == nullptr) {
287294
// Seek over the compressed data.

openvdb/openvdb/math/Math.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <openvdb/Platform.h>
1212
#include <openvdb/version.h>
13+
#include <boost/numeric/conversion/conversion_traits.hpp>
1314
#include <algorithm> // for std::max()
1415
#include <cassert>
1516
#include <cmath> // for std::ceil(), std::fabs(), std::pow(), std::sqrt(), etc.
@@ -915,9 +916,10 @@ enum RotationOrder {
915916
ZXZ_ROTATION
916917
};
917918

918-
template <typename S, typename T, typename = std::enable_if_t<std::is_arithmetic_v<S>&& std::is_arithmetic_v<T>>>
919+
920+
template <typename S, typename T>
919921
struct promote {
920-
using type = typename std::common_type_t<S,T>;
922+
using type = typename boost::numeric::conversion_traits<S, T>::supertype;
921923
};
922924

923925
/// @brief Return the index [0,1,2] of the smallest value in a 3D vector.

pendingchanges/iofix.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Bug Fixes:
2+
- Fix potential crash reading corrupt .vdb files with invalid
3+
blosc or zip chunks. [Fix thanks to Matthias Ueberheide]

0 commit comments

Comments
 (0)