Skip to content

bug: partial download accepted when sha256 is unset — Truncated tar archive on retry #356

Description

@Blazock

Description

When a package has no sha256 declared (e.g. mcpp), a partial/corrupt download can be accepted and cached. On retry (e.g. after switching mirrors), the stale file passes all checks and extraction fails with Truncated tar archive.

Steps to Reproduce

  1. xlings install mcpp -y
  2. Download starts, gets partway through (e.g. 0.0% → partial file written)
  3. Connection drops or user switches mirror
  4. Retry the install — extraction fails with read_data_block: Truncated tar archive detected

Root Cause

The mcpp package (and other XLINGS_RES packages) declares no sha256 checksum. This disables nearly all integrity verification:

  • onVerify callback — skipped (downloader.cppm:462, only set when !task.sha256.empty())
  • Final SHA256 re-check — skipped (downloader.cppm:505)
  • Only protection — size check rejecting files < 1024 bytes (downloader.cppm:489)

The114KB partial file passes the size check. Additionally, the HEAD-based cache path (downloader.cppm:362-410) has an "airline-friendly" fallback: when HEAD fails and a cached file exists with size > 0, it's used as-is — even if truncated.

Observed Behavior

[error] extract failed for mcpp: read_data_block: Truncated tar archive detected while reading data
[error] [mcpp] failed: read_data_block: Truncated tar archive detected while reading data

Cached file: ~/.xlings/data/runtimedir/mcpp-0.0.81-linux-x86_64.tar.gz — only 114KB (expected ~30MB+).

Expected Behavior

A partial/corrupt download should be detected and re-downloaded, not accepted into cache.

Suggested Fix

  1. Add sha256 checksums to all XLINGS_RES package versions (strongest fix)
  2. Enhance size validation when sha256 is absent: compare downloaded file size against Content-Length from the HTTP response, and reject mismatches
  3. Validate archive readability before accepting into cache (try libarchive open + read first header)
  4. Remove the "airline-friendly" HEAD-fail fallback for archives without sha256 — a corrupt cached archive is worse than a re-download

Environment

  • xlings version: current (built from source)
  • Platform: Linux x86_64
  • Package: mcpp@0.0.81

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions