itstool-2.0.4-segfault-1.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Submitted by: DJ Lucas (dj_AT_linuxfromscratch_DOT_org)
  2. Date: 2017-10-26
  3. Initial Package Version: 2.0.4
  4. Upstream Status: Comitted
  5. Origin: https://github.com/itstool/itstool/commit/9b84c007a73e8275ca45762f1bfa3ab7c3a852e2
  6. Description: Fixes memory exhaustion when freeing XML docs.
  7. diff -Naur a/itstool.in b/itstool.in
  8. --- a/itstool.in
  9. +++ a/itstool.in
  10. @@ -477,6 +477,7 @@ class Document (object):
  11. if load_dtd:
  12. ctxt.loadSubset(1)
  13. if keep_entities:
  14. + ctxt.loadSubset(1)
  15. ctxt.ctxtUseOptions(libxml2.XML_PARSE_DTDLOAD)
  16. ctxt.replaceEntities(0)
  17. else:
  18. @@ -1043,6 +1044,7 @@ class Document (object):
  19. if self._load_dtd:
  20. ctxt.loadSubset(1)
  21. if self._keep_entities:
  22. + ctxt.loadSubset(1)
  23. ctxt.ctxtUseOptions(libxml2.XML_PARSE_DTDLOAD)
  24. ctxt.replaceEntities(0)
  25. else:
  26. @@ -1069,7 +1071,9 @@ class Document (object):
  27. ph_node = msg.get_placeholder(child.name).node
  28. if self.has_child_elements(ph_node):
  29. self.merge_translations(translations, None, ph_node, strict=strict)
  30. - child.replaceNode(ph_node)
  31. + newnode = ph_node.copyNode(1)
  32. + newnode.setTreeDoc(self._doc)
  33. + child.replaceNode(newnode)
  34. else:
  35. repl = self.get_translated(ph_node, translations, strict=strict, lang=lang)
  36. child.replaceNode(repl)
  37. @@ -1084,10 +1088,15 @@ class Document (object):
  38. (lang + ' ') if lang is not None else '',
  39. msgstr.encode('utf-8')))
  40. self._xml_err = ''
  41. + ctxt.doc().freeDoc()
  42. return node
  43. retnode = node.copyNode(2)
  44. + retnode.setTreeDoc(self._doc)
  45. for child in xml_child_iter(trnode):
  46. - retnode.addChild(child.copyNode(1))
  47. + newnode = child.copyNode(1)
  48. + newnode.setTreeDoc(self._doc)
  49. + retnode.addChild(newnode)
  50. +
  51. ctxt.doc().freeDoc()
  52. return retnode