+@@ -3783,6 +3789,7 @@
+ pushResources(resDict);
+
+ // save current graphics state
++ GfxState*mystate = state;
+ saveState();
+
+ // kill any pre-existing path
+@@ -3848,6 +3855,9 @@
+
+ // restore graphics state
+ restoreState();
++ if(state!=mystate) {
++ fprintf(stderr, "Invalid state nesting in PDF file- file broken?\n");
++ }
+
+ // pop resource stack
+ popResources();