CVE-2022-36078: Github.com/gagliardetto/binary Binary Vulnerable To Slice Memory Vulnerability

HIGH
Advisory Identifier: GHSA-4p6f-m4f9-ch88
CVSS 8.8
CWE-789 CWE-400
Published
Advisory Summary

CVE-2022-36078 is a HIGH (CVSS 8.8) binary vulnerable to slice memory vulnerability (CWE-789: Memory Allocation with Excessive Size Value) affecting Github.com/gagliardetto/binary libraries in the Go ecosystem. The issue involves binary vulnerable to slice memory allocation with excessive size value. Remediation is available by upgrading affected packages to version 0.7.1.

CVE-2022-36078 at a Glance

CVE Identifier CVE-2022-36078
GHSA Identifier GHSA-4p6f-m4f9-ch88
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-789: Memory Allocation with Excessive Size Value
Affected Product Github.com/gagliardetto/binary
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 8.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2022-36078

To remediate this vulnerability, upgrade all affected Github.com/gagliardetto/binary dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

github.com/gagliardetto/binary fixed: 0.7.1
Upgrade github.com/gagliardetto/binary to 0.7.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for github.com/gagliardetto/binary

How to Check if You Are Affected

To determine whether your application is affected by CVE-2022-36078, inspect your project dependencies for Github.com/gagliardetto/binary:

inspect dependencies for github.com/gagliardetto/binary

Analyze the terminal output to locate any version of Github.com/gagliardetto/binary in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.7.1), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-789: Memory Allocation with Excessive Size Value, where the product allocates memory based on an untrusted, large size value, but it does not ensure that the size is within expected limits, allowing arbitrary amounts of memory to be allocated. In Github.com/gagliardetto/binary, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact > _What kind of vulnerability is it? Who is impacted?_ 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. Example: ```go package main import ( "github.com/gagliardetto/binary" // any version before v0.7.1 is vulnerable "log" ) type MyStruct struct { Field1 []byte // field is a slice (could be a slice of any type) } func main() { // Let's assume that the data is coming from the blockchain: data := []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10} var val MyStruct // - To determine the size of the val.Field1 slice, the decoder will read the length // of the slice from the data itself without any checks on the size of it. // // - This could lead to an allocation of memory with excessive size value. // Which means: []byte{0x01, 0x02, 0x03, 0x04} will be read as the length // of the slice (= 67305985) and then an allocation of memory with 67305985 bytes will be made. // dec := binary.NewBorshDecoder(data) err := dec.Decode(&val) // or binary.UnmarshalBorsh(&val, data) or binary.UnmarshalBin(&val, data) etc. if err != nil { log.Fatal(err) } } ``` ### Patches > _Has the problem been patched? What versions should users upgrade to?_ The vulnerability has been patched in `github.com/gagliardetto/binary` `v0.7.1` Users should upgrade to `v0.7.1` or higher. To upgrade to `v0.7.1` or higher, run: ```bash go get github.com/gagliardetto/binary@v0.7.1 # or go get github.com/gagliardetto/binary@latest ``` ### Workarounds > _Is there a way for users to fix or remediate the vulnerability without upgrading?_ 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. ### References > _Are there any links users can visit to find out more?_ ### For more information If you have any questions or comments about this advisory: * Open an issue in [github.com/gagliardetto/binary](https://github.com/gagliardetto/binary) * DM me on [twitter](https://twitter.com/immaterial_ink)

CVE-2022-36078 Affected Github.com/gagliardetto/binary Versions

1 component(s)
Fixed Versions:
0.7.1
Product / Package Ecosystem Affected Versions Fixed Version
github.com/gagliardetto/binary
Go
< 0.7.1
0.7.1

References

Frequently Asked Questions

What is CVE-2022-36078?
CVE-2022-36078 is a security vulnerability in Github.com/gagliardetto/binary involving Binary vulnerable to Slice Memory Allocation with Excessive Size Value under CWE-789: Memory Allocation with Excessive Size Value.
Which Github.com/gagliardetto/binary versions are affected?
Affected versions include releases prior to 0.7.1 across affected packages: github.com/gagliardetto/binary.
What version fixes CVE-2022-36078?
Upgrading to 0.7.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/gagliardetto/binary affected?
Yes, github.com/gagliardetto/binary is affected in releases prior to 0.7.1. Upgrade your dependency to 0.7.1 or later.
What is the CVSS score of CVE-2022-36078?
CVE-2022-36078 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2022-36078?
CVE-2022-36078 is classified under CWE-789: Memory Allocation with Excessive Size Value (The product allocates memory based on an untrusted, large size value, but it does not ensure that the size is within expected limits, allowing arbitrary amounts of memory to be allocated.).
How can I check Go dependencies for CVE-2022-36078?
Run the dependency tree command: 'inspect dependencies for github.com/gagliardetto/binary'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-4p6f-m4f9-ch88",
  "modified" : "2022-09-16T21:25:03Z",
  "published" : "2022-09-16T21:25:03Z",
  "aliases" : [ "CVE-2022-36078" ],
  "summary" : "Binary vulnerable to Slice Memory Allocation with Excessive Size Value",
  "details" : "### 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)\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/gagliardetto/binary"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.7.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/gagliardetto/binary/security/advisories/GHSA-4p6f-m4f9-ch88"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-36078"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/gagliardetto/binary/pull/7"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/gagliardetto/binary"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/gagliardetto/binary/releases/tag/v0.7.1"
  }, {
    "type" : "WEB",
    "url" : "https://pkg.go.dev/vuln/GO-2022-0963"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-400", "CWE-789" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-09-16T21:25:03Z",
    "nvd_published_at" : "2022-09-02T13:15:00Z"
  }
}