Skip to content

pkg/archive.tarWriter.addFile(): don't change hardlink targets#2357

Merged
openshift-merge-bot[bot] merged 1 commit intocontainers:mainfrom
nalind:hardlinks
Jul 28, 2025
Merged

pkg/archive.tarWriter.addFile(): don't change hardlink targets#2357
openshift-merge-bot[bot] merged 1 commit intocontainers:mainfrom
nalind:hardlinks

Conversation

@nalind
Copy link
Member

@nalind nalind commented Jul 25, 2025

When examining a file that we're adding to an archive to see if it's hard linked to another file that's already been written, or to one that might be written later, only set an entry in the inode->name map that points to the entry we're writing for the first file. This keeps us from writing tar headers with Typeflag==TypeLink and a Linkname that points to another entry with Typeflag==TypeLink in cases where the inode has more than two names.

Fixes containers/buildah#6297.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 25, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nalind

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@nalind
Copy link
Member Author

nalind commented Jul 25, 2025

This reverts what I think was an unintentional part of #2289.

Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mtrmac
Copy link
Collaborator

mtrmac commented Jul 28, 2025

(Should this have a test? I’d merge immediately with a unit test.)

@nalind
Copy link
Member Author

nalind commented Jul 28, 2025

(Should this have a test? I’d merge immediately with a unit test.)

Extended a test to include the case from the original report.

When examining a file that we're adding to an archive to see if it's
hard linked to another file that's already been written, or to one that
might be written later, only set an entry in the inode->name map that
points to the entry we're writing for the first file.  This keeps us
from writing tar headers with Typeflag==TypeLink and a Linkname that
points to another entry with Typeflag==TypeLink in cases where the inode
has more than two names.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Jul 28, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 54892ed into containers:main Jul 28, 2025
20 checks passed
@nalind nalind deleted the hardlinks branch July 28, 2025 15:16
TomSweeneyRedHat pushed a commit to TomSweeneyRedHat/storage that referenced this pull request Jul 31, 2025
… targets

When examining a file that we're adding to an archive to see if it's
hard linked to another file that's already been written, or to one that
might be written later, only set an entry in the inode->name map that
points to the entry we're writing for the first file.  This keeps us
from writing tar headers with Typeflag==TypeLink and a Linkname that
points to another entry with Typeflag==TypeLink in cases where the inode
has more than two names.

Addresses: containers/buildah#6297 for the
release-1.59 branch and eventualy Buildah v1.41.* and Podman v5.6.*

Cherry-pick of containers#2357

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
TomSweeneyRedHat pushed a commit to TomSweeneyRedHat/storage that referenced this pull request Jul 31, 2025
… targets

When examining a file that we're adding to an archive to see if it's
hard linked to another file that's already been written, or to one that
might be written later, only set an entry in the inode->name map that
points to the entry we're writing for the first file.  This keeps us
from writing tar headers with Typeflag==TypeLink and a Linkname that
points to another entry with Typeflag==TypeLink in cases where the inode
has more than two names.

Addresses: containers/buildah#6297 for the
release-1.59 branch and eventualy Buildah v1.41.* and Podman v5.6.*

Cherry-pick of containers#2357

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
jankaluza pushed a commit to containers/container-libs that referenced this pull request Aug 26, 2025
… targets

When examining a file that we're adding to an archive to see if it's
hard linked to another file that's already been written, or to one that
might be written later, only set an entry in the inode->name map that
points to the entry we're writing for the first file.  This keeps us
from writing tar headers with Typeflag==TypeLink and a Linkname that
points to another entry with Typeflag==TypeLink in cases where the inode
has more than two names.

Addresses: containers/buildah#6297 for the
release-1.59 branch and eventualy Buildah v1.41.* and Podman v5.6.*

Cherry-pick of containers/storage#2357

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hardlink layout in the layer changed between v1.40.1 and v1.41.0

2 participants