Skip to content

fix resolve() for cyclically defined objects

Sven M. Hallberg requested to merge selfref into master

It is not entirely clear whether the spec allows cyclic object definitions such as the following:

obj 1 0
1 0 R
endobj

There is an open errata issue about this topic, but no consensus has emerged so far. Most implementations will accept this, however, so for the time being I'm guessing we should, too.

We will treat an object that is defined (directly or indirectly) as itself as equivalent to the null object.

The implementation strategy is to give ourselves an distinct invalid pointer beside NULL and use it to mark the memoization entry for a given cross-reference (ent->obj) as INVALID while we recursively try to resolve it. If we eventually hit an INVALID object, we terminate the process and return NULL. The INVALID entry will internally stay in the memoization slot, but should never be returned by resolve().

Merge request reports