mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
tvg_loader: added tvg format verification
TVG format verification was added on TvgLoader:open()
This commit is contained in:
parent
90dd1b5f98
commit
fa15b9a2af
3 changed files with 14 additions and 8 deletions
|
@ -44,6 +44,8 @@ static tvgBlock _readTvgBlock(const char *ptr)
|
|||
|
||||
static bool _readTvgHeader(const char **ptr)
|
||||
{
|
||||
if (!*ptr) return false;
|
||||
|
||||
//Sign phase, always TVG_BIN_HEADER_SIGNATURE is declared
|
||||
if (memcmp(*ptr, TVG_BIN_HEADER_SIGNATURE, TVG_BIN_HEADER_SIGNATURE_LENGTH)) return false;
|
||||
*ptr += TVG_BIN_HEADER_SIGNATURE_LENGTH;
|
||||
|
@ -52,7 +54,7 @@ static bool _readTvgHeader(const char **ptr)
|
|||
if (memcmp(*ptr, TVG_BIN_HEADER_VERSION, TVG_BIN_HEADER_VERSION_LENGTH)) return false;
|
||||
*ptr += TVG_BIN_HEADER_VERSION_LENGTH;
|
||||
|
||||
//Mata data for proof?
|
||||
//Meta data for proof?
|
||||
uint16_t metaLen;
|
||||
_read_tvg_ui16(&metaLen, *ptr);
|
||||
*ptr += 2;
|
||||
|
@ -502,6 +504,13 @@ static LoaderResult _parsePaint(tvgBlock base_block, Paint **paint)
|
|||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
bool tvgValidateTvgHeader(const char *ptr, uint32_t size)
|
||||
{
|
||||
auto end = ptr + size;
|
||||
if (!_readTvgHeader(&ptr) || ptr >= end) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
unique_ptr<Scene> tvgLoadTvgData(const char *ptr, uint32_t size)
|
||||
{
|
||||
auto end = ptr + size;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "tvgCommon.h"
|
||||
#include "tvgBinaryDesc.h"
|
||||
|
||||
bool tvgValidateTvgHeader(const char *ptr, uint32_t size);
|
||||
unique_ptr<Scene> tvgLoadTvgData(const char *ptr, uint32_t size);
|
||||
|
||||
#endif //_TVG_TVG_LOAD_PARSER_H_
|
||||
|
|
|
@ -79,9 +79,7 @@ bool TvgLoader::open(const string &path)
|
|||
|
||||
pointer = buffer;
|
||||
|
||||
//FIXME: verify TVG format here.
|
||||
|
||||
return true;
|
||||
return tvgValidateTvgHeader(pointer, size);
|
||||
}
|
||||
|
||||
bool TvgLoader::open(const char *data, uint32_t size)
|
||||
|
@ -91,9 +89,7 @@ bool TvgLoader::open(const char *data, uint32_t size)
|
|||
this->pointer = data;
|
||||
this->size = size;
|
||||
|
||||
//FIXME: verify TVG format here.
|
||||
|
||||
return true;
|
||||
return tvgValidateTvgHeader(pointer, size);
|
||||
}
|
||||
|
||||
bool TvgLoader::read()
|
||||
|
|
Loading…
Add table
Reference in a new issue