{"id":"CVE-2022-36078","aliases":["CVE-2022-36078","GHSA-4p6f-m4f9-ch88","GO-2022-0963"],"related":[],"kind":"vulnerability","state":"published","title":"Slice Memory Allocation with Excessive Size Value in binary","summary":"Binary provides encoding/decoding in Borsh and other formats. The vulnerability is a memory allocation vulnerability that can be exploited to allocate slices in memory with (arbitrary) excessive size value, which can either exhaust available memory or crash the whole program. When using `github.com/gagliardetto/binary` to parse unchecked (or wrong type of) data from untrusted sources of input (e.g. the blockchain) into slices, it's possible to allocate memory with excessive size. When `dec.Decode(&val)` method is used to parse data into a structure that is or contains slices of values, the length of the slice was previously read directly from the data itself without any checks on the size of it, and then a slice was allocated. This could lead to an overflow and an allocation of memory with excessive size value. Users should upgrade to `v0.7.1` or higher. A workaround is not to rely on the `dec.Decode(&val)` function to parse the data, but to use a custom `UnmarshalWithDecoder()` method that reads and checks the length of any slice.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Binary provides encoding/decoding in Borsh and other formats. The vulnerability is a memory allocation vulnerability that can be exploited to allocate slices in memory with (arbitrary) excessive size value, which can either exhaust available memory or crash the whole program. When using `github.com/gagliardetto/binary` to parse unchecked (or wrong type of) data from untrusted sources of input (e.g. the blockchain) into slices, it's possible to allocate memory with excessive size. When `dec.Decode(&val)` method is used to parse data into a structure that is or contains slices of values, the length of the slice was previously read directly from the data itself without any checks on the size of it, and then a slice was allocated. This could lead to an overflow and an allocation of memory with excessive size value. Users should upgrade to `v0.7.1` or higher. A workaround is not to rely on the `dec.Decode(&val)` function to parse the data, but to use a custom `UnmarshalWithDecoder()` method that reads and checks the length of any slice.","source":"cvelist"},{"lang":"en","text":"### Impact\n> _What kind of vulnerability is it? Who is impacted?_\n\nThe vulnerability is a memory allocation vulnerability that can be exploited to allocate slices in memory with (arbitrary) excessive size value, which can either exhaust available memory or crash the whole program.\n\nWhen using `github.com/gagliardetto/binary` to parse unchecked (or wrong type of) data from untrusted sources of input (e.g. the blockchain) into slices, it's possible to allocate memory with excessive size.\n\nWhen `dec.Decode(&val)` method is used to parse data into a structure that is or contains slices of values, the length of the slice was previously read directly from the data itself without any checks on the size of it, and then a slice was allocated. This could lead to an overflow and an allocation of memory with excessive size value.\n\nExample:\n\n```go\npackage main\n\nimport (\n\t\"github.com/gagliardetto/binary\" // any version before v0.7.1 is vulnerable\n\t\"log\"\n)\n\ntype MyStruct struct {\n\tField1 []byte // field is a slice (could be a slice of any type)\n}\n\nfunc main() {\n\t// Let's assume that the data is coming from the blockchain:\n\tdata := []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}\n\t\n\tvar val MyStruct\n\t// - To determine the size of the val.Field1 slice, the decoder will read the length\n\t//   of the slice from the data itself without any checks on the size of it.\n\t//\n\t// - This could lead to an allocation of memory with excessive size value.\n\t//   Which means: []byte{0x01, 0x02, 0x03, 0x04} will be read as the length\n\t//   of the slice (= 67305985) and then an allocation of memory with 67305985 bytes will be made.\n\t//\n\tdec := binary.NewBorshDecoder(data)\n\terr := dec.Decode(&val)  // or binary.UnmarshalBorsh(&val, data) or binary.UnmarshalBin(&val, data) etc.\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n\n### Patches\n> _Has the problem been patched? What versions should users upgrade to?_\n\nThe vulnerability has been patched in `github.com/gagliardetto/binary` `v0.7.1`\n\nUsers should upgrade to `v0.7.1` or higher.\n\nTo upgrade to `v0.7.1` or higher, run:\n\n```bash\ngo get github.com/gagliardetto/binary@v0.7.1\n\n# or\n\ngo get github.com/gagliardetto/binary@latest\n```\n\n### Workarounds\n> _Is there a way for users to fix or remediate the vulnerability without upgrading?_\n\nA workaround is not to rely on the `dec.Decode(&val)` function to parse the data, but to use a custom `UnmarshalWithDecoder()` method that reads and checks the length of any slice.\n\n### References\n> _Are there any links users can visit to find out more?_\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open an issue in [github.com/gagliardetto/binary](https://github.com/gagliardetto/binary)\n* DM me on [twitter](https://twitter.com/immaterial_ink)","format":"markdown","source":"ghsa"},{"lang":"en","text":"A memory allocation vulnerability can be exploited to allocate arbitrarily large slices, which can exhaust available memory or crash the program.\n\nWhen parsing data from untrusted sources of input (e.g. the blockchain), the length of the slice to allocate is read directly from the data itself without any checks, which could lead to an allocation of excessive memory.","format":"markdown","source":"go"},{"lang":"es","text":"Binary proporciona codificación/decodificación en Borsh y otros formatos. La vulnerabilidad es un fallo de asignación de memoria que puede ser explotada para asignar fragmentos en la memoria con un valor de tamaño (arbitrario) excesivo, que puede agotar la memoria disponible o bloquear todo el programa. Cuando es usada \"github.com/gagliardetto/binary\" para analizar datos no verificados (o de tipo incorrecto) procedentes de fuentes de entrada no confiables (por ejemplo, la cadena de bloques) en trozos, es posible asignar memoria con un tamaño excesivo. Cuando es usado el método \"dec.Decode(&amp;val)\" para parsear datos en una estructura que es o contiene trozos de valores, la longitud del trozo es leído previamente directamente de los propios datos sin ninguna comprobación del tamaño de los mismos, y luego es asignado un trozo. Esto podría conllevar a un desbordamiento y una asignación de memoria con un valor de tamaño excesivo. Los usuarios deberían actualizar a versiones \"v0.7.1\" o superiores. Una mitigación es no confiar en la función \"dec.Decode(&amp;val)\" para analizar los datos, sino usar un método personalizado \"UnmarshalWithDecoder()\" que lea y compruebe la longitud de cualquier slice","source":"nvd"}],"published":"2022-09-02T12:15:14.000Z","modified":"2026-06-17T04:52:52.237Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"}],"cwes":["CWE-400","CWE-789","CWE-1284"],"affected":[{"ranges":[{"version":"< 0.7.1","status":"affected"}],"vendor":"gagliardetto","product":"binary","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"0.7.1"}],"ecosystem":"Go","package":"github.com/gagliardetto/binary","purl":"pkg:golang/github.com/gagliardetto/binary","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"0.7.1"}],"ecosystem":"Go","package":"github.com/gagliardetto/binary","purl":"pkg:golang/github.com/gagliardetto/binary","source":"go"},{"ranges":[{"status":"affected","fixed":"0.7.1"}],"vendor":"binary_project","product":"binary","cpe":"cpe:2.3:a:binary_project:binary:*:*:*:*:*:go:*:*","source":"nvd"}],"references":[{"url":"https://github.com/gagliardetto/binary/security/advisories/GHSA-4p6f-m4f9-ch88","tags":["advisory","exploit","mitigation","third-party-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/gagliardetto/binary/pull/7","tags":["fix","issue-tracking","patch","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/gagliardetto/binary/releases/tag/v0.7.1","tags":["release-notes","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2022-36078","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/gagliardetto/binary","tags":["package"],"sources":["ghsa"]},{"url":"https://pkg.go.dev/vuln/GO-2022-0963","tags":["web"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2025-04-22T15:42:32.400Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2022-36078","url":"https://www.cve.org/CVERecord?id=CVE-2022-36078","licence":"CVE Terms of Use","modified":"2025-04-22T17:40:53.728Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-4p6f-m4f9-ch88","url":"https://github.com/advisories/GHSA-4p6f-m4f9-ch88","licence":"CC-BY-4.0","modified":"2023-11-08T04:09:59.881Z"},{"source":"go","name":"Go Vulnerability Database","id":"GO-2022-0963","url":"https://pkg.go.dev/vuln/GO-2022-0963","licence":"CC-BY-4.0","modified":"2024-05-20T16:03:47.000Z"},{"source":"nvd","name":"NVD","id":"CVE-2022-36078","url":"https://nvd.nist.gov/vuln/detail/CVE-2022-36078","licence":"Public domain","modified":"2026-06-17T04:52:52.237Z"}],"updatedAt":"2026-11-25T22:58:14.645Z","epss":{"score":0.01242,"percentile":0.70082,"date":"2026-12-02T12:00:21.000Z"}}