Skip to content

mutate.Extract will export wrong content when have a hard link and later modify it. (under special conditions) #2002

Description

@hunshcn

Describe the bug

Make a file and create a hard link to it, if this file is not the first file in tar (In general, it is in dictionary order).
And then modify this file, the content from crane export of the hard link file will be wrong.

To Reproduce

FROM busybox

RUN echo 123 > t2
RUN ln t2 t1 && ln t2 t3
RUN echo 456 > t1
# prepare dockerfile
docker build . -t xxx
docker push xxx
crane export xxx image.tar && tar xf image.tar
cat t1 t2 t3

or I have built a image and pushed to dockerhub,
just use it

crane export hunsh/ggcr-extract-hardlink image.tar && tar xf image.tar
cat t1 t2 t3

will get output

456
123
456

Expected behavior

456
123
123

Additional context

It's related to #977

Add any other context about the problem here.

  • Output of crane version: 0.20.2
  • Registry used (e.g., GCR, ECR, Quay)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions