mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
lottie: fixed a parsing error in assets
An unused key in assets parsing corrupted the sequence. This change now ensures they are tightly ignored.
This commit is contained in:
parent
a2defaf694
commit
21252632b3
2 changed files with 15 additions and 30 deletions
|
@ -850,27 +850,10 @@ void LottieParser::parseObject(Array<LottieObject*>& parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LottieImage* LottieParser::parseImage(const char* key)
|
LottieImage* LottieParser::parseImage(const char* data, const char* subPath, bool embedded)
|
||||||
{
|
{
|
||||||
//Used for Image Asset
|
//Used for Image Asset
|
||||||
const char* data = nullptr;
|
|
||||||
const char* subPath = nullptr;
|
|
||||||
auto embedded = false;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (!strcmp(key, "u")) {
|
|
||||||
subPath = getString();
|
|
||||||
} else if (!strcmp(key, "p")) {
|
|
||||||
data = getString();
|
|
||||||
} else if (!strcmp(key, "e")) {
|
|
||||||
embedded = getInt();
|
|
||||||
} else skip(key);
|
|
||||||
} while ((key = nextObjectKey()));
|
|
||||||
|
|
||||||
if (!data) return nullptr;
|
|
||||||
|
|
||||||
auto image = new LottieImage;
|
auto image = new LottieImage;
|
||||||
if (!image) return nullptr;
|
|
||||||
|
|
||||||
//embeded image resource. should start with "data:"
|
//embeded image resource. should start with "data:"
|
||||||
//header look like "data:image/png;base64," so need to skip till ','.
|
//header look like "data:image/png;base64," so need to skip till ','.
|
||||||
|
@ -879,7 +862,6 @@ LottieImage* LottieParser::parseImage(const char* key)
|
||||||
auto mimeType = data + 11;
|
auto mimeType = data + 11;
|
||||||
auto needle = strstr(mimeType, ";");
|
auto needle = strstr(mimeType, ";");
|
||||||
image->mimeType = strDuplicate(mimeType, needle - mimeType);
|
image->mimeType = strDuplicate(mimeType, needle - mimeType);
|
||||||
|
|
||||||
//b64 data
|
//b64 data
|
||||||
auto b64Data = strstr(data, ",") + 1;
|
auto b64Data = strstr(data, ",") + 1;
|
||||||
size_t length = strlen(data) - (b64Data - data);
|
size_t length = strlen(data) - (b64Data - data);
|
||||||
|
@ -904,24 +886,27 @@ LottieObject* LottieParser::parseAsset()
|
||||||
LottieObject* obj = nullptr;
|
LottieObject* obj = nullptr;
|
||||||
char *id = nullptr;
|
char *id = nullptr;
|
||||||
|
|
||||||
|
//Used for Image Asset
|
||||||
|
const char* data = nullptr;
|
||||||
|
const char* subPath = nullptr;
|
||||||
|
auto embedded = false;
|
||||||
|
|
||||||
while (auto key = nextObjectKey()) {
|
while (auto key = nextObjectKey()) {
|
||||||
if (!strcmp(key, "id")) {
|
if (!strcmp(key, "id"))
|
||||||
|
{
|
||||||
if (peekType() == kStringType) {
|
if (peekType() == kStringType) {
|
||||||
id = getStringCopy();
|
id = getStringCopy();
|
||||||
} else {
|
} else {
|
||||||
id = _int2str(getInt());
|
id = _int2str(getInt());
|
||||||
}
|
}
|
||||||
//Precomposition asset
|
|
||||||
} else if (!strcmp(key, "layers")) {
|
|
||||||
obj = parseLayers();
|
|
||||||
} else if (!strcmp(key, "w") || !strcmp(key, "h") || !strcmp(key, "nm") || !strcmp(key, "fr")) {
|
|
||||||
skip(key);
|
|
||||||
//Image asset
|
|
||||||
} else {
|
|
||||||
obj = parseImage(key);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(key, "layers")) obj = parseLayers();
|
||||||
|
else if (!strcmp(key, "u")) subPath = getString();
|
||||||
|
else if (!strcmp(key, "p")) data = getString();
|
||||||
|
else if (!strcmp(key, "e")) embedded = getInt();
|
||||||
|
else skip(key);
|
||||||
}
|
}
|
||||||
|
if (data) obj = parseImage(data, subPath, embedded);
|
||||||
if (obj) obj->name = id;
|
if (obj) obj->name = id;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ private:
|
||||||
|
|
||||||
LottieObject* parseObject();
|
LottieObject* parseObject();
|
||||||
LottieObject* parseAsset();
|
LottieObject* parseAsset();
|
||||||
LottieImage* parseImage(const char* key);
|
LottieImage* parseImage(const char* data, const char* subPath, bool embedded);
|
||||||
LottieLayer* parseLayer();
|
LottieLayer* parseLayer();
|
||||||
LottieObject* parseGroup();
|
LottieObject* parseGroup();
|
||||||
LottieRect* parseRect();
|
LottieRect* parseRect();
|
||||||
|
|
Loading…
Add table
Reference in a new issue