From af81076105a8d3906345aaa4a2f0e7fbbbb13f23 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Tue, 30 Jul 2019 17:24:34 +0900 Subject: [PATCH] lottieparser: Stop parsing if the media type is unlikely to lottie. Users may need to try a load data in a brutal-force way, if they have no idea of input source. This case, they have no choices but try using all methods to find out which loader successfully loaded among various media loaders. This is a common scenario for compatible media support. --- src/lottie/lottieparser.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/lottie/lottieparser.cpp b/src/lottie/lottieparser.cpp index 4a0df3641b..c4cb9c1009 100644 --- a/src/lottie/lottieparser.cpp +++ b/src/lottie/lottieparser.cpp @@ -170,11 +170,9 @@ protected: class LottieParserImpl : public LookaheadParserHandler { public: LottieParserImpl(char *str, const char *dir_path) - : LookaheadParserHandler(str), mDirPath(dir_path) - { - ParseNext(); - } - void ParseNext(); + : LookaheadParserHandler(str), mDirPath(dir_path) {} + bool VerifyType(); + bool ParseNext(); public: bool EnterObject(); bool EnterArray(); @@ -280,17 +278,26 @@ LookaheadParserHandler::LookaheadParserHandler(char *str) r_.IterativeParseInit(); } -void LottieParserImpl::ParseNext() +bool LottieParserImpl::VerifyType() +{ + /* Verify the media type is lottie json. + Could add more strict check. */ + return ParseNext(); +} + +bool LottieParserImpl::ParseNext() { if (r_.HasParseError()) { st_ = kError; - return; + return false; } if (!r_.IterativeParseNext(ss_, *this)) { vCritical << "Lottie file parsing error"; - RAPIDJSON_ASSERT(0); + st_ = kError; + return false; } + return true; } bool LottieParserImpl::EnterObject() @@ -2244,7 +2251,10 @@ LottieParser::~LottieParser() = default; LottieParser::LottieParser(char *str, const char *dir_path) : d(std::make_unique(str, dir_path)) { - d->parseComposition(); + if (d->VerifyType()) + d->parseComposition(); + else + vWarning << "Input data is not Lottie format!"; } std::shared_ptr LottieParser::model()