Repository navigation
[ELD] Diagnose tar archives given as input files - #2061
Open
Ricardo Alves de Souza (ricardoasouz) wants to merge 1 commit into
Open
Ricardo Alves de Souza (ricardoasouz) wants to merge 1 commit into
Ricardo Alves de Souza (ricardoasouz) wants to merge 1 commit into
Conversation
Input files that are not ELF, bitcode or ar archive files are parsed as linker scripts. A tar archive therefore reached the script lexer, which printed a note echoing the binary contents for each NUL byte before the parser failed. Recognize tar archives by the checksum of their first header block, which covers v7 headers (they have no magic) as well as ustar, GNU and pax ones. Check it before an input is handled as a linker script, so the archive gets a single error and is never recorded or lexed as one: Error: a.tar: tar archives cannot be used as input files Scripts named with -T, INCLUDE, --version-script, --dynamic-list or --extern-list are not sniffed and are unaffected, as are inputs read with -b binary. Fixes qualcomm#2042 Signed-off-by: Ricardo Alves de Souza <ricardoasouz@hotmail.com>
Ricardo Alves de Souza (ricardoasouz)
requested a review
from quic-areg
as a code owner
October 4, 2026 09:59
Shankar Easwaran (quic-seaswara)
approved these changes
Oct 5, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2042
Inputs that aren't ELF, bitcode or ar archives are parsed as linker scripts, so a tar file went through the script lexer, which printed a note with the raw header bytes for every NUL it hit before the parser gave up.
This adds
InputTarReader::isTarArchive(), which checks the checksum of the first header block. That also catches v7 archives, which have no magic, along with ustar, GNU and pax. The check is at the top of the linker script branch inObjectLinker::readAndProcessInput(), mirroring how executables without--just-symbolsare rejected, so the file is never recorded or lexed as a script:Only inputs whose type ELD infers are affected (command line,
INPUT(),GROUP()). Files passed with-T,INCLUDE,--version-script,--dynamic-listor--extern-listbehave as before, and so does-b binary. I can extend the check to those options, or add a hint to the message (e.g.--replayfor reproduce tarballs), if you think it's worth it.GNU ld and lld don't catch this either, both parse the file as a script and fail with a parse error.
Tests: unit tests in
TarReaderTests(ustar, pax, v7 and non-tar data) and a lit test inCommon/standalone/Sniffingcovering the reported case,INPUT(),GROUP()and-b binary. The lit test fails without the change, and check-eld-extended shows no new failures compared to main.