Skip to content

detect old (v7) tar headers when routing archives - #40

Open
abdul-khaliq-khalid wants to merge 1 commit into
google:mainfrom
abdul-khaliq-khalid:v7-tar-detection
Open

detect old (v7) tar headers when routing archives#40
abdul-khaliq-khalid wants to merge 1 commit into
google:mainfrom
abdul-khaliq-khalid:v7-tar-detection

Conversation

@abdul-khaliq-khalid

Copy link
Copy Markdown

Tar detection keys on the ustar magic at offset 257, but old (v7) archives carry no magic there at all, yet tarfile.open(mode="r:*") reads them fine. A v7 tar therefore never reaches _extract_and_scan_archive and none of its members get scanned, so the same malicious pickle that scores unsafe: 3 inside a ustar tar scores unsafe: 0 inside a v7 one. Repacking an archive as v7 is enough to slip a pickle past the scan.

has_tar_header keeps the ustar fast path and falls back to verifying the 512-byte header checksum at offset 148, which is how magic-less v7 headers are normally identified; the two 262-byte peeks became 512 so the checksum is actually available. I put it in utils and routed the five inline copies of the check through it so the formats stay in agreement, and I confirmed gnu/pax/zip/gzip and benign inputs classify exactly as before, with no false positives across 20k random 512-byte blobs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant