Fix: Add security asserts.
parent
c82a6d05b0
commit
63dae0a7f2
|
@ -47,48 +47,59 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/cfileio.h>
|
||||
#include <assimp/IOStream.hpp>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/ai_assert.h>
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
class CIOSystemWrapper;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Custom IOStream implementation for the C-API
|
||||
class CIOStreamWrapper : public IOStream {
|
||||
/// @brief Custom IOStream implementation for the C-API-
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class CIOStreamWrapper final : public IOStream {
|
||||
public:
|
||||
explicit CIOStreamWrapper(aiFile *pFile, CIOSystemWrapper *io) :
|
||||
mFile(pFile),
|
||||
mIO(io) {}
|
||||
~CIOStreamWrapper(void);
|
||||
|
||||
size_t Read(void *pvBuffer, size_t pSize, size_t pCount);
|
||||
size_t Write(const void *pvBuffer, size_t pSize, size_t pCount);
|
||||
aiReturn Seek(size_t pOffset, aiOrigin pOrigin);
|
||||
size_t Tell(void) const;
|
||||
size_t FileSize() const;
|
||||
void Flush();
|
||||
explicit CIOStreamWrapper(aiFile *pFile, CIOSystemWrapper *io);
|
||||
~CIOStreamWrapper() override;
|
||||
size_t Read(void *pvBuffer, size_t pSize, size_t pCount) override;
|
||||
size_t Write(const void *pvBuffer, size_t pSize, size_t pCount) override;
|
||||
aiReturn Seek(size_t pOffset, aiOrigin pOrigin) override;
|
||||
size_t Tell(void) const override;
|
||||
size_t FileSize() const override;
|
||||
void Flush() override;
|
||||
|
||||
private:
|
||||
aiFile *mFile;
|
||||
CIOSystemWrapper *mIO;
|
||||
};
|
||||
|
||||
class CIOSystemWrapper : public IOSystem {
|
||||
inline CIOStreamWrapper::CIOStreamWrapper(aiFile *pFile, CIOSystemWrapper *io) :
|
||||
mFile(pFile),
|
||||
mIO(io) {
|
||||
ai_assert(io != nullptr);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/// @brief Custom IO-System wrapper implementation for the C-API.
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class CIOSystemWrapper final : public IOSystem {
|
||||
friend class CIOStreamWrapper;
|
||||
|
||||
public:
|
||||
explicit CIOSystemWrapper(aiFileIO *pFile) :
|
||||
mFileSystem(pFile) {}
|
||||
|
||||
bool Exists(const char *pFile) const;
|
||||
char getOsSeparator() const;
|
||||
IOStream *Open(const char *pFile, const char *pMode = "rb");
|
||||
void Close(IOStream *pFile);
|
||||
explicit CIOSystemWrapper(aiFileIO *pFile);
|
||||
~CIOSystemWrapper() override = default;
|
||||
bool Exists(const char *pFile) const override;
|
||||
char getOsSeparator() const override;
|
||||
IOStream *Open(const char *pFile, const char *pMode = "rb") override;
|
||||
void Close(IOStream *pFile) override;
|
||||
|
||||
private:
|
||||
aiFileIO *mFileSystem;
|
||||
};
|
||||
|
||||
inline CIOSystemWrapper::CIOSystemWrapper(aiFileIO *pFile) : mFileSystem(pFile) {
|
||||
ai_assert(pFile != nullptr);
|
||||
}
|
||||
|
||||
} // namespace Assimp
|
||||
|
||||
#endif
|
||||
#endif // AI_CIOSYSTEM_H_INCLUDED
|
||||
|
|
Loading…
Reference in New Issue