-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#261: recursion in page tree parsing. avoid with storing the current …
…path and identifying cycles
- Loading branch information
Showing
8 changed files
with
193 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
/* | ||
Source File : PDFParsingPath.cpp | ||
Copyright 2011 Gal Kahana PDFWriter | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include "PDFParsingPath.h" | ||
#include "Trace.h" | ||
|
||
#include <sstream> | ||
|
||
|
||
using namespace std; | ||
using namespace PDFHummus; | ||
|
||
PDFParsingPath::PDFParsingPath() { | ||
|
||
} | ||
|
||
|
||
EStatusCode PDFParsingPath::EnterObject(ObjectIDType inObjectId) { | ||
ObjectIDTypeList::iterator it = find(mObjectsPath.begin(), mObjectsPath.end(), inObjectId); | ||
if(it != mObjectsPath.end()) { | ||
TRACE_LOG2("PDFParsingPath::EnterObject, attempting to enter object %ld, where the object already exists in the current path: %s",inObjectId,PrintPath().c_str()); | ||
return eFailure; | ||
} | ||
|
||
mObjectsPath.push_back(inObjectId); | ||
return eSuccess; | ||
} | ||
|
||
EStatusCode PDFParsingPath::ExitObject(ObjectIDType inObjectId) { | ||
if(mObjectsPath.size() == 0 || mObjectsPath.back() != inObjectId) { | ||
TRACE_LOG2("PDFParsingPath::ExitObject, attempting to exit object %ld, where the object is NOT the last entered: %s",inObjectId,PrintPath().c_str()); | ||
return eFailure; | ||
} | ||
|
||
mObjectsPath.pop_back(); | ||
return eSuccess; | ||
|
||
} | ||
|
||
void PDFParsingPath::Reset() { | ||
mObjectsPath.clear(); | ||
} | ||
|
||
std::string PDFParsingPath::PrintPath() { | ||
std::stringstream pathWriter; | ||
ObjectIDTypeList::iterator it = mObjectsPath.begin(); | ||
|
||
if(it != mObjectsPath.end()) { | ||
pathWriter<<*it; | ||
for(; it != mObjectsPath.end(); ++it) { | ||
pathWriter<<", "<<*it; | ||
} | ||
} | ||
|
||
return pathWriter.str(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Source File : PDFParsingPath.h | ||
Copyright 2011 Gal Kahana PDFWriter | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include "EStatusCode.h" | ||
#include "ObjectsBasicTypes.h" | ||
|
||
#include <list> | ||
#include <string> | ||
|
||
|
||
typedef std::list<ObjectIDType> ObjectIDTypeList; | ||
|
||
|
||
class PDFParsingPath { | ||
|
||
public: | ||
PDFParsingPath(); | ||
|
||
PDFHummus::EStatusCode EnterObject(ObjectIDType inObjectId); | ||
PDFHummus::EStatusCode ExitObject(ObjectIDType inObjectId); | ||
|
||
void Reset(); | ||
private: | ||
|
||
ObjectIDTypeList mObjectsPath; | ||
|
||
std::string PrintPath(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "PDFParser.h" | ||
#include "InputFile.h" | ||
#include "Trace.h" | ||
|
||
#include "testing/TestIO.h" | ||
|
||
#include <iostream> | ||
|
||
using namespace std; | ||
using namespace PDFHummus; | ||
|
||
int PDFParserFuzzSanity(int argc, char* argv[]) { | ||
PDFParser parser; | ||
InputFile pdfFile; | ||
|
||
std::string path = argv[3]; | ||
|
||
EStatusCode status = pdfFile.OpenFile(path); | ||
if(status != PDFHummus::eSuccess) | ||
{ | ||
cout<<"unable to open file for reading, Path:"<<path.c_str()<<"\n"; | ||
return 1; | ||
} | ||
|
||
// traces on | ||
Trace::DefaultTrace().SetLogSettings(BuildRelativeOutputPath(argv, "PDFParserFuzzSanity.txt"), true, true); | ||
|
||
// checks that returns, status doesn't matter | ||
parser.StartPDFParsing(pdfFile.GetInputStream()); | ||
|
||
return status; | ||
} |