Add checks for invalid buffer ans size (#5570)

pull/5571/head
Kim Kulling 2024-05-13 08:55:10 +02:00 committed by GitHub
parent 47dbabadcd
commit 325b0a543f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View File

@ -233,8 +233,13 @@ const aiScene *aiImportFileFromMemoryWithProperties(
unsigned int pFlags,
const char *pHint,
const aiPropertyStore *props) {
ai_assert(nullptr != pBuffer);
ai_assert(0 != pLength);
if (pBuffer == nullptr) {
return nullptr;
}
if (pLength == 0u) {
return nullptr;
}
const aiScene *scene = nullptr;
ASSIMP_BEGIN_EXCEPTION_REGION();

View File

@ -60,3 +60,12 @@ TEST_F( AssimpAPITest, aiGetLastErrorTest ) {
const char *error = aiGetErrorString();
EXPECT_NE(nullptr, error);
}
TEST_F(AssimpAPITest, aiImportFileFromMemoryTest) {
const aiScene *scene_null_buffer = aiImportFileFromMemory(nullptr, 0u, 0u, nullptr);
EXPECT_EQ(nullptr, scene_null_buffer);
char buffer[1024] = {'\0'};
const aiScene *scene_null_size = aiImportFileFromMemory(buffer, 0u, 0u, nullptr);
EXPECT_EQ(nullptr, scene_null_size);
}