From 33ea9e7d6503ea488156c260bd13873076ab6f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Tue, 28 Sep 2021 15:01:04 +0200 Subject: [PATCH] Raise an exception if no EBX_HANDLER is found in PDF --- include/libgourou_common.h | 1 + src/libgourou.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/libgourou_common.h b/include/libgourou_common.h index d14b054..5af33ac 100644 --- a/include/libgourou_common.h +++ b/include/libgourou_common.h @@ -68,6 +68,7 @@ namespace gourou enum DOWNLOAD_ERROR { DW_NO_ITEM = 0x1200, + DW_NO_EBX_HANDLER, }; enum SIGNIN_ERROR { diff --git a/src/libgourou.cpp b/src/libgourou.cpp index f336b96..bbbe447 100644 --- a/src/libgourou.cpp +++ b/src/libgourou.cpp @@ -611,7 +611,8 @@ namespace gourou else if (res == PDF) { uPDFParser::Parser parser; - + bool EBXHandlerFound = false; + try { GOUROU_LOG(DEBUG, "Parse PDF"); @@ -631,6 +632,7 @@ namespace gourou // Update EBX_HANDLER with rights if ((*it)->hasKey("Filter") && (**it)["Filter"]->str() == "/EBX_HANDLER") { + EBXHandlerFound = true; uPDFParser::Object* ebx = (*it)->clone(); (*ebx)["ADEPT_ID"] = new uPDFParser::String(item->getResource()); (*ebx)["EBX_BOOKID"] = new uPDFParser::String(item->getResource()); @@ -642,7 +644,12 @@ namespace gourou } } - parser.write(path, true); + if (EBXHandlerFound) + parser.write(path, true); + else + { + EXCEPTION(DW_NO_EBX_HANDLER, "EBX_HANDLER not found"); + } } return res;