Merge pull request #3068 from ms-maxvollmer/GLTF2_invalid_buffer_fix

GLTF2: ExtractData now throws exception instead of returning false if data is invalid
pull/3070/head^2
Kim Kulling 2020-04-16 11:28:38 +02:00 committed by GitHub
commit 1e74fe85bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -376,7 +376,7 @@ struct Accessor : public Object {
inline uint8_t *GetPointer(); inline uint8_t *GetPointer();
template<class T> template<class T>
bool ExtractData(T *&outData); void ExtractData(T *&outData);
void WriteData(size_t count, const void *src_buffer, size_t src_stride); void WriteData(size_t count, const void *src_buffer, size_t src_stride);

View File

@ -614,9 +614,12 @@ inline void CopyData(size_t count,
} // namespace } // namespace
template<class T> template<class T>
bool Accessor::ExtractData(T *&outData) { void Accessor::ExtractData(T *&outData)
{
uint8_t* data = GetPointer(); uint8_t* data = GetPointer();
if (!data) return false; if (!data) {
throw DeadlyImportError("GLTF: data is NULL");
}
const size_t elemSize = GetElementSize(); const size_t elemSize = GetElementSize();
const size_t totalSize = elemSize * count; const size_t totalSize = elemSize * count;
@ -636,8 +639,6 @@ bool Accessor::ExtractData(T *&outData) {
memcpy(outData + i, data + i * stride, elemSize); memcpy(outData + i, data + i * stride, elemSize);
} }
} }
return true;
} }
inline void Accessor::WriteData(size_t _count, const void *src_buffer, size_t src_stride) { inline void Accessor::WriteData(size_t _count, const void *src_buffer, size_t src_stride) {