Vulnerabilities in pkg:golang/github.com/ipld/go-car

PACKAGE
Advisory Summary

GHSA-9x4h-8wgm-8xfg is a MODERATE malformed car panics and excessive vulnerability (CWE-400: Uncontrolled Resource Consumption) affecting Github.com/ipld/go car libraries in the Go ecosystem. The issue involves malformed car panics and excessive memory usage. Remediation is available by upgrading affected packages to version 0.4.0, 2.4.0.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:golang/github.com/ipld/go-car

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:golang/github.com/ipld/go-car. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-9x4h-8wgm-8xfg - MODERATE Malformed CAR panics and excessive memory usage

GHSA-9x4h-8wgm-8xfg at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-9x4h-8wgm-8xfg
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-400: Uncontrolled Resource Consumption
Affected Product Github.com/ipld/go car
Package Ecosystem Go
Published Date
Last Updated

How to Fix GHSA-9x4h-8wgm-8xfg

To remediate this vulnerability, upgrade all affected Github.com/ipld/go car 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/ipld/go-car fixed: 0.4.0
Upgrade github.com/ipld/go-car to 0.4.0
github.com/ipld/go-car/v2 fixed: 2.4.0
Upgrade github.com/ipld/go-car/v2 to 2.4.0
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/ipld/go-car

How to Check if You Are Affected

To determine whether your application is affected by GHSA-9x4h-8wgm-8xfg, inspect your project dependencies for Github.com/ipld/go car:

inspect dependencies for github.com/ipld/go-car

Analyze the terminal output to locate any version of Github.com/ipld/go car in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.4.0), 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-400: Uncontrolled Resource Consumption, where the product does not properly control the allocation and maintenance of a limited resource. In Github.com/ipld/go car, 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 **Versions impacted** * `<=` go-car@v0.3.3 * `<=` go-car@v2.3.0 **Description** Decoding CAR data from untrusted user input can cause: - Panics: - Out of bound memory access - Out of memory - Divide by zero - Excessive memory usage Such panics can be triggered by intentionally malformed CARv1 data, including CARv1 data within a CARv2 container; and also CARv2 data with excessively large indexes. These vulnerabilities are not known to be exploited in the wild and were discovered primarily with the use of code fuzzing tooling. **Details** **Out of bound memory access** (OOB), **out of memory** (OOM) panics or **excessive memory usage** can be triggered by decode of malformed CARv1 headers, malformed CARv1 sections, and malformed CIDv0 data used in CARv1 sections. This also applies to CARv1 data within a CARv2 container. Additionally, we wish to use this security advisory to make clear to consumers of CARv2 format data that **loading CARv2 indexes from untrusted sources is dangerous and should be avoided**. Where CAR data indexes are required, they should be regenerated locally. Out of memory (OOM) panics or excessive memory usage can be triggered by decode of intentionally malformed CARv2 indexes, or CARv2 indexes which are larger than available system memory (i.e. parallelization of CARv2 decodes may increase such a vulnerability). ### Patches **Fixed versions** * `>=` go-car@v0.4.0 * `>=` go-car@v2.4.0 **Description of user-facing changes** ***go-car@v0.4.0*** imposes a fixed maximum header length and section length of 32 MiB during decode. Headers exceeding this length will cause the decoder to return an error as the initial CAR decode occurs. Sections (the combination of CID and block data) exceeding this length will cause the decoder to return an error as that section is read. The default maximum of 32 MiB may be changed _globally_ in an application instance by directly changing the `MaxAllowedSectionSize` variable in the `github.com/ipld/go-car/util` package. We recommend that users of go-car@v0 upgrade to go-car@v2, where these maximums may be applied per-decode rather than globally. ***go-car@v2.4.0*** imposes a default maximum header length of 32 MiB and a default maximum section length of 8 MiB. Headers exceeding this length will cause the decoder to return an error as the initial CAR decode occurs. Sections (the combination of CID and block data) exceeding this length will cause the decoder to return an error as that section is read. The default values may be adjusted by supplying a `MaxAllowedHeaderSize(x)` or `MaxAllowedSectionSize(y)` option to any decode function that accepts options. These include: * `OpenReader()` * `NewReader()` * `NewBlockReader()` * `ReadVersion()` * `LoadIndex()` * `GenerateIndex()` * `ReadOrGenerateIndex()` * `WrapV1()` * `ExtractV1File()` * `ReplaceRootsInFile()` * `blockstore/NewBlockReader()` * `blockstore/NewReadOnly()` * `blockstore/OpenReadOnly()` * `blockstore/OpenReadWrite()` Please be aware that the default values are **very generous** and may be lowered where a user wants to impose restrictions closer to typical sizes. * Typical header lengths should be in the order of 60 bytes, but the CAR format does not specify a maximum number of roots a header may contain. The default maximum of 32 MiB makes room for novel uses of the CAR format. * Typical IPLD block sizes are under 2 MiB, and it is generally recommended that they not be above 1 MiB for maximum interoperability (e.g. there are hard limitations when sharing IPLD data with IPFS). CARv1 sections are the concatenation of CID and block bytes. The default maximum section length of 8 MiB makes room for novel IPLD data. ***go-car@v2.4.0*** introduces a new API that can be used to inspect a CAR and check for various errors, including those detailed in this advisory. The `Reader#Inspect(bool)` API returns a `Stats` object with various details about the CAR, such as its version, number of blocks, and details about codecs and multihashers used. When its argument is `true`, it will also perform a full hash consistency check of blocks contained within the CAR to ensure they match the CIDs. When `false`, block data is skipped over so a scan will likely be more efficient than reading blocks through a `BlockReader` if statistics and/or validity checking is all that's required. Note that `Inspect()` does minimal checking of index data; the strong recommendation is that if index data is untrusted then it should be regenerated. ***go-car@v2.4.0*** also includes additional documentation regarding the dangers of consuming CARv2 index data from untrusted sources and a recommendation to regenerate indexes of CAR data from such sources where an index is required. ### Workarounds There are no workarounds for vulnerabilities in impacted versions decoding CARv1 data. Users of impacted versions should avoid accepting CAR data from untrusted sources. OOM or excessive memory usage vulnerabilities resulting from CARv2 index parsing in impacted versions can be avoided by not reading indexes from CARv2 data from untrusted sources. ### References Details on the CARv1 and CARv2 formats, including the composition of CARv1 headers and sections, and CARv2 indexes can be found in the CAR format specifications: https://ipld.io/specs/transport/car/ ### For more information If you have any questions or comments about this advisory please open an issue in [go-car](https://github.com/ipld/go-car).

GHSA-9x4h-8wgm-8xfg Affected Github.com/ipld/go car Versions

2 component(s)
Fixed Versions:
0.4.02.4.0
Product / Package Ecosystem Affected Versions Fixed Version
github.com/ipld/go-car
Go
< 0.4.0
0.4.0
github.com/ipld/go-car/v2
Go
≥ 2.0.0
< 2.4.0
2.4.0

References

Frequently Asked Questions

What is GHSA-9x4h-8wgm-8xfg?
GHSA-9x4h-8wgm-8xfg is a security vulnerability in Github.com/ipld/go car involving Malformed CAR panics and excessive memory usage under CWE-400: Uncontrolled Resource Consumption.
Which Github.com/ipld/go car versions are affected?
Affected versions include releases prior to 0.4.0, 2.4.0 across affected packages: github.com/ipld/go-car, github.com/ipld/go-car/v2.
What version fixes GHSA-9x4h-8wgm-8xfg?
Upgrading to 0.4.0, 2.4.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/ipld/go-car affected?
Yes, github.com/ipld/go-car is affected in releases prior to 0.4.0. Upgrade your dependency to 0.4.0 or later.
Is github.com/ipld/go-car/v2 affected?
Yes, github.com/ipld/go-car/v2 is affected in releases prior to 2.4.0. Upgrade your dependency to 2.4.0 or later.
What CWE is associated with GHSA-9x4h-8wgm-8xfg?
GHSA-9x4h-8wgm-8xfg is classified under CWE-400: Uncontrolled Resource Consumption (The product does not properly control the allocation and maintenance of a limited resource.).
How can I check Go dependencies for GHSA-9x4h-8wgm-8xfg?
Run the dependency tree command: 'inspect dependencies for github.com/ipld/go-car'. 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-9x4h-8wgm-8xfg",
  "modified" : "2022-07-06T19:26:17Z",
  "published" : "2022-07-06T19:26:17Z",
  "aliases" : [ ],
  "summary" : "Malformed CAR panics and excessive memory usage",
  "details" : "### Impact\n\n**Versions impacted**\n  * `<=` go-car@v0.3.3\n  * `<=` go-car@v2.3.0\n\n**Description**\n\nDecoding CAR data from untrusted user input can cause:\n\n- Panics:\n  - Out of bound memory access\n  - Out of memory\n  - Divide by zero\n- Excessive memory usage\n\nSuch panics can be triggered by intentionally malformed CARv1 data, including CARv1 data within a CARv2 container; and also CARv2 data with excessively large indexes.\n\nThese vulnerabilities are not known to be exploited in the wild and were discovered primarily with the use of code fuzzing tooling.\n\n**Details**\n\n**Out of bound memory access** (OOB), **out of memory** (OOM) panics or **excessive memory usage** can be triggered by decode of malformed CARv1 headers, malformed CARv1 sections, and malformed CIDv0 data used in CARv1 sections. This also applies to CARv1 data within a CARv2 container.\n\nAdditionally, we wish to use this security advisory to make clear to consumers of CARv2 format data that **loading CARv2 indexes from untrusted sources is dangerous and should be avoided**. Where CAR data indexes are required, they should be regenerated locally. Out of memory (OOM) panics or excessive memory usage can be triggered by decode of intentionally malformed CARv2 indexes, or CARv2 indexes which are larger than available system memory (i.e. parallelization of CARv2 decodes may increase such a vulnerability).\n\n### Patches\n\n**Fixed versions**\n\n* `>=` go-car@v0.4.0\n* `>=` go-car@v2.4.0\n\n**Description of user-facing changes**\n\n***go-car@v0.4.0*** imposes a fixed maximum header length and section length of 32 MiB during decode. Headers exceeding this length will cause the decoder to return an error as the initial CAR decode occurs. Sections (the combination of CID and block data) exceeding this length will cause the decoder to return an error as that section is read.\n\nThe default maximum of 32 MiB may be changed _globally_ in an application instance by directly changing the `MaxAllowedSectionSize` variable in the `github.com/ipld/go-car/util` package.\n\nWe recommend that users of go-car@v0 upgrade to go-car@v2, where these maximums may be applied per-decode rather than globally.\n\n***go-car@v2.4.0*** imposes a default maximum header length of 32 MiB and a default maximum section length of 8 MiB. Headers exceeding this length will cause the decoder to return an error as the initial CAR decode occurs. Sections (the combination of CID and block data) exceeding this length will cause the decoder to return an error as that section is read.\n\nThe default values may be adjusted by supplying a `MaxAllowedHeaderSize(x)` or `MaxAllowedSectionSize(y)` option to any decode function that accepts options. These include:\n\n* `OpenReader()`\n* `NewReader()`\n* `NewBlockReader()`\n* `ReadVersion()`\n* `LoadIndex()`\n* `GenerateIndex()`\n* `ReadOrGenerateIndex()`\n* `WrapV1()`\n* `ExtractV1File()`\n* `ReplaceRootsInFile()`\n* `blockstore/NewBlockReader()`\n* `blockstore/NewReadOnly()`\n* `blockstore/OpenReadOnly()`\n* `blockstore/OpenReadWrite()`\n\nPlease be aware that the default values are **very generous** and may be lowered where a user wants to impose restrictions closer to typical sizes.\n\n* Typical header lengths should be in the order of 60 bytes, but the CAR format does not specify a maximum number of roots a header may contain. The default maximum of 32 MiB makes room for novel uses of the CAR format.\n* Typical IPLD block sizes are under 2 MiB, and it is generally recommended that they not be above 1 MiB for maximum interoperability (e.g. there are hard limitations when sharing IPLD data with IPFS). CARv1 sections are the concatenation of CID and block bytes. The default maximum section length of 8 MiB makes room for novel IPLD data.\n\n***go-car@v2.4.0*** introduces a new API that can be used to inspect a CAR and check for various errors, including those detailed in this advisory. The `Reader#Inspect(bool)` API returns a `Stats` object with various details about the CAR, such as its version, number of blocks, and details about codecs and multihashers used. When its argument is `true`, it will also perform a full hash consistency check of blocks contained within the CAR to ensure they match the CIDs. When `false`, block data is skipped over so a scan will likely be more efficient than reading blocks through a `BlockReader` if statistics and/or validity checking is all that's required. Note that `Inspect()` does minimal checking of index data; the strong recommendation is that if index data is untrusted then it should be regenerated.\n\n***go-car@v2.4.0*** also includes additional documentation regarding the dangers of consuming CARv2 index data from untrusted sources and a recommendation to regenerate indexes of CAR data from such sources where an index is required.\n\n### Workarounds\n\nThere are no workarounds for vulnerabilities in impacted versions decoding CARv1 data. Users of impacted versions should avoid accepting CAR data from untrusted sources.\n\nOOM or excessive memory usage vulnerabilities resulting from CARv2 index parsing in impacted versions can be avoided by not reading indexes from CARv2 data from untrusted sources.\n\n### References\n\nDetails on the CARv1 and CARv2 formats, including the composition of CARv1 headers and sections, and CARv2 indexes can be found in the CAR format specifications: https://ipld.io/specs/transport/car/\n\n### For more information\n\nIf you have any questions or comments about this advisory please open an issue in [go-car](https://github.com/ipld/go-car).",
  "severity" : [ ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/ipld/go-car"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.4.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/ipld/go-car/v2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0"
      }, {
        "fixed" : "2.4.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/ipld/go-car/security/advisories/GHSA-9x4h-8wgm-8xfg"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/ipld/go-car"
  }, {
    "type" : "WEB",
    "url" : "https://pkg.go.dev/vuln/GO-2022-0503"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-400" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-07-06T19:26:17Z",
    "nvd_published_at" : null
  }
}