Skip to content

Docker image unpacker#715

Open
paulnoalhyt wants to merge 35 commits into
masterfrom
feature/docker_image_unpacker
Open

Docker image unpacker#715
paulnoalhyt wants to merge 35 commits into
masterfrom
feature/docker_image_unpacker

Conversation

@paulnoalhyt
Copy link
Copy Markdown
Collaborator

@paulnoalhyt paulnoalhyt commented Mar 3, 2026

  • I have reviewed the OFRAK contributor guide and attest that this pull request is in accordance with it.
  • I have made or updated a changelog entry for the changes in this pull request.

One sentence summary of this PR (This should go in the CHANGELOG!)

Docker image tarball unpacker.

Link to Related Issue(s)

Please describe the changes in your request.

Adds a Docker image unpacker: unpack a docker image tar ball to a filesystem that represents the filesystem from this image once run as a container. This unpacker walks the different image layers and applies them, including whiteouts and opaque whiteouts.

Anyone you think should look at this, specifically?

No

@rbs-jacob
Copy link
Copy Markdown
Member

Is there a technical reason this depends on those other branches, or is it just a result of your local git tree? I'm assuming the latter, but want to know what I should look out for when reviewing.

@paulnoalhyt
Copy link
Copy Markdown
Collaborator Author

No, it doesn't technically depend on those other branches, it's just that I need all these features for the project I'm currently working on.

@paulnoalhyt paulnoalhyt requested a review from rbs-jacob May 13, 2026 10:42
Copy link
Copy Markdown
Member

@rbs-jacob rbs-jacob left a comment

Choose a reason for hiding this comment

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

Some small stuff, then this should be good to go!

Comment on lines +156 to +157
entry = entry.strip("/")
basename = os.path.basename(entry)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might also want to call os.path.normpath in case there are leading ./.

with open(manifest_path) as f:
manifest = json.load(f)

layers = manifest[0]["Layers"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why only pick the first entry? I'm pretty sure (~75%) Docker can bundle multiple images in the same output tarball. Might be worth at least emitting a warning here if there are more than one?

Comment on lines +173 to +177
raise NotImplementedError(
"Packing a DockerImage back into a Docker image tarball is not supported. "
"The current unpacker merges all layers into a single filesystem, so the original "
"layer structure cannot be reconstructed."
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Based on the comment in this error, I'm assuming the answer is "no," but: can we just use the TarPacker here to not specifically implement an image packer?

Since this is probably not possible, feel free to resolve this without comment if that's the case.

Comment on lines +95 to +104
class TestDockerImagePacker:
async def test_pack_not_implemented(self, ofrak_context: OFRAKContext):
with open(DOCKER_IMAGE_ASSET, "rb") as f:
data = f.read()
resource = await ofrak_context.create_root_resource("docker.tar", data)
await resource.identify()

await resource.unpack()
with pytest.raises(NotImplementedError):
await resource.pack()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I get that we might have to do this for test coverage, but it feels weird to assert that the packer is unimplemented in a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants