{
  "id": "opencv/io-imdecode-corrupt-data",
  "signature": "cv::error: (-215:Assertion failed) !buf.empty() && buf.data != NULL in function 'cv::imdecode'",
  "signature_zh": "cv::error: (-215:断言失败) !buf.empty() && buf.data != NULL 在函数 'cv::imdecode' 中",
  "regex": "cv::error: \\(-215:Assertion failed\\) !buf\\.empty\\(\\) && buf\\.data != NULL in function 'cv::imdecode'",
  "domain": "opencv",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "The input buffer to imdecode is empty or contains corrupt image data that cannot be decoded.",
  "root_cause_type": "generic",
  "root_cause_zh": "imdecode 的输入缓冲区为空或包含无法解码的损坏图像数据。",
  "versions": [
    {
      "version": "4.7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Attempting to decode a buffer read from a file that was truncated mid-write",
      "why_fails": "Truncated data is still non-empty but corrupt; imdecode will fail silently or with assertion error.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Passing a buffer that was decoded from base64 without proper validation",
      "why_fails": "Base64 decoding may produce empty or invalid binary data if the input string is malformed.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Validate the buffer before decoding: check that buf.size() > 0 and optionally check the first few bytes for a valid image signature (e.g., JPEG: 0xFF 0xD8, PNG: 0x89 0x50). Example in C++: if (buf.size() < 4 || buf[0] != 0xFF || buf[1] != 0xD8) { /* handle error */ }.",
      "success_rate": 0.95,
      "how": "Validate the buffer before decoding: check that buf.size() > 0 and optionally check the first few bytes for a valid image signature (e.g., JPEG: 0xFF 0xD8, PNG: 0x89 0x50). Example in C++: if (buf.size() < 4 || buf[0] != 0xFF || buf[1] != 0xD8) { /* handle error */ }.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If reading from a network stream, use a robust HTTP client that checks Content-Length and verifies the response body is complete before passing to imdecode.",
      "success_rate": 0.85,
      "how": "If reading from a network stream, use a robust HTTP client that checks Content-Length and verifies the response body is complete before passing to imdecode.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Validate the buffer before decoding: check that buf.size() > 0 and optionally check the first few bytes for a valid image signature (e.g., JPEG: 0xFF 0xD8, PNG: 0x89 0x50). Example in C++: if (buf.size() < 4 || buf[0] != 0xFF || buf[1] != 0xD8) { /* handle error */ }.",
    "If reading from a network stream, use a robust HTTP client that checks Content-Length and verifies the response body is complete before passing to imdecode."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.opencv.org/4.x/d4/da8/group__imgcodecs.html#ga26a67788faa58ade337f8d28ba0eb19e",
  "official_doc_section": null,
  "error_code": "-215",
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-05-18",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}