Skip to content

Commit 4cce955

Browse files
authored
Merge pull request #1487 from kmuseth/security_fix_in_NanoVDB
replaced sprintf with snprintf to prevent future bufferoverflow
2 parents bdad566 + 1e12efa commit 4cce955

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

nanovdb/nanovdb/NanoVDB.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122

123123
#define NANOVDB_MAJOR_VERSION_NUMBER 32 // reflects changes to the ABI and hence also the file format
124124
#define NANOVDB_MINOR_VERSION_NUMBER 4 // reflects changes to the API but not ABI
125-
#define NANOVDB_PATCH_VERSION_NUMBER 0 // reflects changes that does not affect the ABI or API
125+
#define NANOVDB_PATCH_VERSION_NUMBER 1 // reflects changes that does not affect the ABI or API
126126

127127
// This replaces a Coord key at the root level with a single uint64_t
128128
#define USE_SINGLE_ROOT_KEY
@@ -161,7 +161,7 @@ typedef unsigned long long uint64_t;
161161
#include <stdint.h> // for types like int32_t etc
162162
#include <stddef.h> // for size_t type
163163
#include <cassert> // for assert
164-
#include <cstdio> // for sprinf
164+
#include <cstdio> // for snprintf
165165
#include <cmath> // for sqrt and fma
166166
#include <limits> // for numeric_limits
167167
#include <utility>// for std::move
@@ -673,8 +673,8 @@ class Version
673673
#ifndef __CUDACC_RTC__
674674
const char* c_str() const
675675
{
676-
char *buffer = (char*)malloc(4 + 1 + 4 + 1 + 4 + 1);// xxxx.xxxx.xxxx\n
677-
sprintf(buffer, "%d.%d.%d", this->getMajor(), this->getMinor(), this->getPatch());
676+
char *buffer = (char*)malloc(4 + 1 + 4 + 1 + 4 + 1);// xxxx.xxxx.xxxx\0
677+
snprintf(buffer, 4 + 1 + 4 + 1 + 4 + 1, "%d.%d.%d", this->getMajor(), this->getMinor(), this->getPatch()); // Prevents overflows by enforcing a fixed size of buffer
678678
return buffer;
679679
}
680680
#endif
@@ -5688,7 +5688,7 @@ void writeUncompressedGrid(StreamT &os, const void *buffer)
56885688
if (*(const uint32_t*)(grid+24) >= *(const uint32_t*)(grid+28) - 1) break;
56895689
grid += gridSize;
56905690
}
5691-
}
5691+
}// writeUncompressedGrid
56925692

56935693
/// @brief write multiple NanoVDB grids to a single file, without compression.
56945694
template<typename GridHandleT, template<typename...> class VecT>
@@ -5709,7 +5709,7 @@ void writeUncompressedGrids(const char* fileName, const VecT<GridHandleT>& handl
57095709
fprintf(stderr, "nanovdb::writeUncompressedGrids: Unable to open file \"%s\"for output\n",fileName); exit(EXIT_FAILURE);
57105710
}
57115711
for (auto &handle : handles) writeUncompressedGrid(os, handle.data());
5712-
}
5712+
}// writeUncompressedGrids
57135713

57145714
/// @brief read all uncompressed grids from a stream and return their handles.
57155715
///
@@ -5741,7 +5741,7 @@ VecT<GridHandleT> readUncompressedGrids(StreamT& is, const typename GridHandleT:
57415741
}
57425742
}
57435743
return handles;
5744-
}
5744+
}// readUncompressedGrids
57455745

57465746
/// @brief Read a multiple un-compressed NanoVDB grids from a file and return them as a vector.
57475747
template<typename GridHandleT, template<typename...> class VecT>
@@ -5767,7 +5767,7 @@ VecT<GridHandleT> readUncompressedGrids(const char *fileName, const typename Gri
57675767
fprintf(stderr, "nanovdb::readUncompressedGrids: Unable to open file \"%s\"for input\n",fileName); exit(EXIT_FAILURE);
57685768
}
57695769
return readUncompressedGrids<GridHandleT, StreamT, VecT>(is, buffer);
5770-
}
5770+
}// readUncompressedGrids
57715771

57725772
} // namespace io
57735773

nanovdb/nanovdb/PNanoVDB.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ PNANOVDB_FORCE_INLINE float pnanovdb_read_half(pnanovdb_buf_t buf, pnanovdb_addr
632632

633633
#define PNANOVDB_MAJOR_VERSION_NUMBER 32// reflects changes to the ABI
634634
#define PNANOVDB_MINOR_VERSION_NUMBER 4// reflects changes to the API but not ABI
635-
#define PNANOVDB_PATCH_VERSION_NUMBER 0// reflects bug-fixes with no ABI or API changes
635+
#define PNANOVDB_PATCH_VERSION_NUMBER 1// reflects bug-fixes with no ABI or API changes
636636

637637
#define PNANOVDB_GRID_TYPE_UNKNOWN 0
638638
#define PNANOVDB_GRID_TYPE_FLOAT 1

pendingchanges/nanovdb.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ Improvements:
1818
Bug Fixes:
1919
- Fixed a bug in nanovdb::HostBuffer that could produce crashes due to misaligned CPU memory allocations.
2020
- Fixed bug related to uninitialized memory in nanovdb::Grid which could confuse CRC32 checksum validation.
21-
- Fixed bugs related to the use of intrinsic functions for fast bit-counting in nanovdb.
21+
- Fixed bugs related to the use of intrinsic functions for fast bit-counting in nanovdb.
22+
- Fixed a potential security vulnerability in NanoVDB.h related to buffer overflow exploits.

0 commit comments

Comments
 (0)