Upon exception xml_to_boxes() drops the fz_html_tree passed to it.
Consider the case where write_rich_content() calls fz_new_story()
to create a fz_story (which contains fz_html_tree). Upon
exception write_rich_content() drops the fz_story, but it also
calls fz_place_story() which ends up in convert_to_boxes(), which
calls xml_to_boxes(). If an exception is thrown here, then first
xml_to_boxes() will drop the fz_story's fz_html_tree, and later
write_rich_content() will also drop the same fz_story and its
fz_html_tree .
The only other function that calls xml_to_boxes() is
fz_parse_html_tree() which is only called by fz_parse_html()
which upon exception also drops the fz_html_tree is has created.
The conclusion is that the functions, write_rich_content() and
fz_parse_html_tree(), retain ownership of the fz_html_tree they
created, and consequently drop their fz_html_tree's upon
exception, while xml_to_boxes() erroneously assumes that it takes
ownership of the fz_html_tree passed to it.
The fix is to remove the drop from xml_to_boxes().
This fixes oss-fuzz issue
396958483.