PDF/XPS: fix potential heap overflow