Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archive/tar: automatically promote zero-value Header.Typeflag to TypeReg #22768

Closed
dsnet opened this issue Nov 16, 2017 · 2 comments
Closed

archive/tar: automatically promote zero-value Header.Typeflag to TypeReg #22768

dsnet opened this issue Nov 16, 2017 · 2 comments
Milestone

Comments

@dsnet
Copy link
Member

dsnet commented Nov 16, 2017

When people construct their own tar.Header, it is common to see something like:

tw.WriteHeader(&tar.Header{
	Name: "VERSION",
	Mode: 0644,
	Size: int64(len(version)),
}

This does not set Typeflag: tar.TypeReg and so uses the zero value of Typeflag, which is TypeRegA.
The relevant specification says:

0 represents a regular file. For backwards-compatibility, a typeflag value of binary zero ( '\0' ) should be recognized as meaning a regular file when extracting files from the archive. Archives written with this version of the archive file format create regular files with a typeflag value of the ISO/IEC 646:1991 standard IRV '0'.

Thus, the zero value should be interpreted by readers as equivalent to TypeReg. Every tar reader I know of properly does this. However, it seems like a good idea to have the Writer promote TypeRegA to TypeReg as I can't think of any reason why the user would explicitly want to encode TypeRegA.

Similarly, perhaps the Reader should automatically promote TypeRegA to TypeReg so that users don't have to keep putting both versions in their switch statements.

\cc @bradfitz

@dsnet dsnet added this to the Go1.11 milestone Nov 16, 2017
@bradfitz
Copy link
Contributor

SGTM

@dsnet dsnet self-assigned this Nov 16, 2017
@gopherbot
Copy link

Change https://golang.org/cl/85656 mentions this issue: archive/tar: normalize TypeRegA to TypeReg when possible

@dsnet dsnet removed their assignment Jan 9, 2018
@golang golang locked and limited conversation to collaborators Feb 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants