Commit 178fdef4 authored by Albert Astals Cid's avatar Albert Astals Cid Committed by Albert Astals Cid

Rework Parser::makeStream "entry" variable handling

Scopes the entry variable so people don't try to use it in between
parent 426834db
Pipeline #7857 passed with stage
in 11 minutes and 28 seconds
......@@ -198,16 +198,19 @@ Stream *Parser::makeStream(Object &&dict, Guchar *fileKey,
Stream *str;
Goffset length;
Goffset pos, endPos;
XRefEntry *entry = nullptr;
if (xref && (entry = xref->getEntry(objNum, false))) {
if (!entry->getFlag(XRefEntry::Parsing) ||
(objNum == 0 && objGen == 0)) {
entry->setFlag(XRefEntry::Parsing, true);
} else {
error(errSyntaxError, getPos(),
"Object '{0:d} {1:d} obj' is being already parsed", objNum, objGen);
return nullptr;
if (xref) {
XRefEntry *entry = xref->getEntry(objNum, false);
if (entry) {
if (!entry->getFlag(XRefEntry::Parsing) ||
(objNum == 0 && objGen == 0)) {
entry->setFlag(XRefEntry::Parsing, true);
} else {
error(errSyntaxError, getPos(),
"Object '{0:d} {1:d} obj' is being already parsed", objNum, objGen);
return nullptr;
}
}
}
......@@ -230,10 +233,6 @@ Stream *Parser::makeStream(Object &&dict, Guchar *fileKey,
length = 0;
}
// the above dictLookup can cause a xref reconstruction if the file is damaged
// so we need to update the entry pointer
entry = xref ? xref->getEntry(objNum, false) : nullptr;
// check for length in damaged file
if (xref && xref->getStreamEnd(pos, &endPos)) {
length = endPos - pos;
......@@ -295,8 +294,15 @@ Stream *Parser::makeStream(Object &&dict, Guchar *fileKey,
// get filters
str = str->addFilters(str->getDict(), recursion);
if (entry)
entry->setFlag(XRefEntry::Parsing, false);
if (xref) {
// Don't try to reuse the entry from the block at the start
// of the function, xref can change in the middle because of
// reconstruction
XRefEntry *entry = xref->getEntry(objNum, false);
if (entry) {
entry->setFlag(XRefEntry::Parsing, false);
}
}
return str;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment