# CVE-2018-13347: PYSEC-2018-89 - mpatch.c in Mercurial before 4.6.1 mishandles integer addition and subtraction, aka OVE-20180430-0002.

Source: https://junglewise.ai/threats/cve-2018-13347-mercurial-integer-overflow-in-mpatch-c  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2018-07-06. Updated: 2026-09-26  
License: CC BY 4.0 with a link back

CVE-2018-13347 · Severity: low · CVSS 3 · Published 2018-07-06

Mercurial is a distributed version control system used by development teams to manage source code. An integer overflow vulnerability in the patch application logic (mpatch.c) can allow an attacker to cause a buffer underflow or memory corruption when processing specially crafted patch files, potentially enabling arbitrary code execution or service disruption.

Technologies: [mercurial (PyPI)](https://junglewise.ai/threats/technologies/mercurial). Vendors: [PyPI](https://junglewise.ai/threats/vendors/pypi).

## Quick answers

**Is CVE-2018-13347 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2018-13347 being exploited in the wild.

**How severe is CVE-2018-13347?** Low severity, with a CVSS score of 3, published 6 July 2018.

**Which products and versions are affected?** mercurial (PyPI) ECOSYSTEM:introduced=0,fixed=4.6.1.

**Is there a fix for CVE-2018-13347?** Yes. mercurial (PyPI): upgrade to 4.6.1 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2018-13347 attacked?** It is attacked over the network.

**Am I affected by CVE-2018-13347?** Check whether you run mercurial (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- mercurial (PyPI): upgrade to 4.6.1 or later

  ```sh
  pip install "mercurial>=4.6.1"
  ```


## Technical details

The vulnerability exists in mpatch.c in Mercurial before version 4.6.1, where integer addition and subtraction operations are not properly validated, leading to integer overflow conditions (CWE-190). The vulnerable mpatch_apply() function mishandles fragment position calculations when processing binary patches, causing a buffer underflow. An attacker can craft a malicious patch file that, when applied by Mercurial, triggers the overflow and corrupts memory. No authentication or special privileges are required; the attack only requires an attacker to supply a malicious patch file to a Mercurial repository. Patches are available in Mercurial 4.6.1 and later.

## Affected products

- Mercurial Mercurial before 4.6.1

## Identifiers

- CVE-2018-13347
- GHSA-3mjj-mr4f-qxmx
- PYSEC-2018-89

## Timeline

- 2018-07-06: disclosed
- 2018-06-06: patched: Mercurial 4.6.1 released

## References

- [https://access.redhat.com/errata/RHSA-2019:2276](https://access.redhat.com/errata/RHSA-2019:2276)

## Related threats

- [PYSEC-2026-666 - Mercurial Directory traversal vulnerability](https://junglewise.ai/threats/cve-2008-2942-mercurial-directory-traversal-vulnerability)
- [PYSEC-2026-665 - Mercurial Improper Certificate Validation vulnerability](https://junglewise.ai/threats/cve-2010-4237-mercurial-improper-certificate-validation-vulnerability)
- [JGit Improper Input Validation vulnerability](https://junglewise.ai/threats/cve-2014-9390-jgit-improper-input-validation-vulnerability)
- [Mercurial Path Traversal/Link Following vulnerability](https://junglewise.ai/threats/cve-2019-3902-mercurial-path-traversal-link-following-vulnerability)
- [PYSEC-2018-91 - cext/manifest.c in Mercurial before 4.7.2 has an out-of-bounds read during parsing of a malformed manifest entry.](https://junglewise.ai/threats/cve-2018-17983-mercurial-out-of-bounds-read-vulnerability)
