google / google/go-containerregistry

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

Open
#2,002 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
4k
Forks
686
Avg merge
2d 12h
Merged PRs (30d)
26

Description

### 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

```Dockerfile
FROM busybox

RUN echo 123 > t2
RUN ln t2 t1 && ln t2 t3
RUN echo 456 > t1
```
```bash
# 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 https://github.com/google/go-containerregistry/issues/977

Add any other context about the problem here.

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.