avoid crash on document ending before contained table ends

Change-Id: I003b7e00673cd5a4b4f0ed5218e2d30cfef04ffb