cpio: an entry with mtime 0 is treated as "no mtime" (empty `Modified`, extracted file gets the current time)

Aperta Adatta ai principianti
#305 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

Inizia da CPP/7zip/Archive/CpioHandler.cpp, in particolare da GetProperty(kpidMTime) intorno alle righe 903–907, poi esamina i punti di analisi dell’header cpio indicati nel rapporto. Rimuovi la condizione che tratta un timestamp pari a 0 come assente oppure tieni traccia del fatto che il campo sia definito. Verifica, usando i comandi di riproduzione nell’issue, che l’elenco e l’estrazione preservino una voce con mtime 0.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Environment
  • 7-Zip (z) 26.06 (arm64), ip7z/7zip @ d3296e3, built with CPP/7zip/cmpl_mac_arm64.mak (Bundles/Alone2)
  • macOS 26.4.1 arm64, Apple clang 21.0.0; /usr/bin/tar = bsdtar 3.5.3 (libarchive 3.7.4)
Description

CpioHandler.cpp stores the header time in a UInt32 and uses 0 as "not defined". A cpio entry whose real time stamp is 0 (1970-01-01T00:00:00Z) is reported without a modification time, so x does not set the file time and the file keeps the extraction time.

Steps to reproduce
Z=7zz
d=/tmp/verify4_LAR002; rm -rf "$d"; mkdir -p "$d/s" "$d/o" && cd "$d"
printf hello > s/f.txt
python3 -c "import os; os.utime('s/f.txt',(0,0))"
(cd s && /usr/bin/tar --no-mac-metadata --no-xattrs --format newc -cf ../a.cpio f.txt)
$Z l -slt a.cpio | grep -E '^(Path|Modified)'
$Z x -y -bd -oo a.cpio >/dev/null
python3 -c "import os,time; print('extracted mtime', int(os.stat('o/f.txt').st_mtime), 'now', int(time.time()))"

Output (two runs):

Path = f.txt
Modified = 
extracted mtime 1795585129 now 1795585129

With mtime 1 or 2 (same commands, os.utime(..., (1,1))) the output is Modified = 1970-01-01 08:00:01 (host TZ UTC+8) and extracted mtime 1. --format cpio and --format bin behave like newc; --format ustar with mtime 0 gives Modified = 1970-01-01 08:00:00 and extracted mtime 0.

Expected

The cpio header time field (POSIX odc c_mtime, SVR4 newc c_mtime) is a plain number of seconds since the Epoch; the formats define no "unset" value. 0 must be reported as 1970-01-01 00:00:00 UTC and restored on extraction, as for ustar/pax/zip/7z in 7-Zip and as bsdtar -tvf / bsdtar -x do. (Format specification text not re-fetched; based on the cpio(5) description of the fields.)

Actual

Modified is empty and the extracted file has the current time. Exit code 0.

Root cause (analysis on d3296e3)

CPP/7zip/Archive/CpioHandler.cpp:903-907, GetProperty(kpidMTime):

case kpidMTime:
{
  if (item.MTime != 0)
    PropVariant_SetFrom_UnixTime(prop, item.MTime);
  break;
}

item.MTime is a UInt32 filled at lines 355 (G32(16, item.MTime)), 392-394 and 420 (READ_HEX (5, item.MTime)). The code cannot tell "0" from "absent". With an empty property the extract code does not call the file-time setter.

Suggested fix

Always return the time for cpio items (every cpio header has the field), or add a separate MTime_Defined flag. Remove the != 0 test.


Found with a differential test setup (a model of the documented behavior, and for some reports an independent tool such as libarchive/bsdtar, compared against the real binary) and then checked by hand: every command above was re-run verbatim on the tested build, and the root cause was read in the source. Tested commit: d3296e3 (26.06).

Lingua principale
C++
Stelle
4.6k
Fork
519
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ip7z/7zip

Tutte le issue di ip7z/7zip

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.