xar: `<name enctype="base64">` is not decoded; non-ASCII entry names are listed and extracted as base64 text

Open
#298 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
backend

Research direction

Start with CPP/7zip/Archive/XarHandler.cpp around lines 430–431, where the name element text is read, and inspect how the XML parser exposes element attributes. Then review CPP/7zip/Archive/Base64Handler.cpp for existing decoding behavior. Done means xar names marked enctype="base64" are decoded when listed and extracted; verify against both reproducer archives and their expected 中文.txt name.

Written by the indexing model from the issue text.

Description

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); /usr/bin/xar (Apple)
Description

xar writers store a file name that is not plain ASCII as <name enctype="base64">...</name> in the TOC. 7-Zip reads the element text without looking at enctype.

Steps to reproduce
Z=7zz
d=/tmp/verify4_LAR003; rm -rf "$d"; mkdir -p "$d/s" "$d/o" && cd "$d"
printf hello > "s/中文.txt"
(cd s && /usr/bin/tar --no-mac-metadata --no-xattrs --format xar -cf ../l.xar "中文.txt")
(cd s && /usr/bin/xar -cf ../a.xar "中文.txt")
for f in l.xar a.xar; do rm -rf o; mkdir o; echo "== $f ref: $(/usr/bin/tar -tf $f 2>/dev/null | head -1)"; $Z l -slt $f | awk '/^Path = /{print "   7zz:", $3}' | tail -n +2; $Z x -y -bd -oo $f >/dev/null; ls o; done

Output (two runs, identical):

== l.xar ref: 中文.txt
   7zz: 5Lit5paHLnR4dA==
   7zz: [TOC].xml
5Lit5paHLnR4dA==
[TOC].xml
== a.xar ref: 中文.txt
   7zz: 5Lit5paHLnR4dA==
   7zz: [TOC].xml
5Lit5paHLnR4dA==
[TOC].xml

The TOC of l.xar contains <name enctype="base64">5Lit5paHLnR4dA==</name> (repro/lar003.sh prints it).

Expected

The name 中文.txt, as shown by bsdtar -tf for both archives. The xar wiki format page only says "The table of contents is an XML document. The table of contents should be encoded as UTF-8." (https://github.com/mackyle/xar/wiki/xarformat); the enctype attribute is not described there, but both Apple's xar and libarchive write and read it.

Actual

7zz lists and extracts the file as 5Lit5paHLnR4dA==. rc=0.

Root cause (analysis on d3296e3)

CPP/7zip/Archive/XarHandler.cpp:430-431:

file.Name = item.GetSubStringForTag("name");
z7_xml_DecodeString(file.Name);

GetSubStringForTag() returns the element text and z7_xml_DecodeString() only decodes XML entities. A grep for enctype/base64 in XarHandler.cpp finds nothing, so the attribute is never read.

Suggested fix

Find the name sub-item (FindSubTag_GetPtr("name")), read GetPropVal("enctype"), and when it equals base64 decode the text before storing it in file.Name. No shared Base64 decoder helper was found under CPP/Common/; the only Base64 code is the format handler CPP/7zip/Archive/Base64Handler.cpp, so a small decoder has to be added or factored out.


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).

Dominant language
C++
Stars
4.6k
Forks
519
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ip7z/7zip

All issues in ip7z/7zip

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.