Skip to content

Commit 46c7b2d

Browse files
author
Roy Lin
committed
test(box): set uid/gid in synthetic layer tarballs (root extraction)
The oci::layers/oci::rootfs test helpers built GNU tar headers without uid/gid, leaving those octal fields blank. A root-side extraction (which preserves ownership, euid==0) then failed to parse the uid ("numeric field was not a number"), so 9 tests failed on a root host (e.g. the KVM release runner) while passing as non-root. Real OCI layers — and the production build-layer code — always set uid/gid, so this was purely a malformed test fixture. Set uid/gid=0 in both helpers.
1 parent 0995553 commit 46c7b2d

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/runtime/src/oci/layers.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ mod tests {
326326
let mut header = tar::Header::new_gnu();
327327
header.set_size(content.len() as u64);
328328
header.set_mode(0o644);
329+
// Set uid/gid explicitly: a bare GNU header leaves those octal fields
330+
// blank, which makes a root-side extraction with preserved ownership
331+
// fail to parse the uid ("numeric field was not a number"). Real OCI
332+
// layers always carry valid uid/gid fields.
333+
header.set_uid(0);
334+
header.set_gid(0);
329335
header.set_cksum();
330336

331337
builder.append_data(&mut header, name, *content).unwrap();

src/runtime/src/oci/rootfs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,10 @@ mod tests {
493493
let mut header = tar::Header::new_gnu();
494494
header.set_size(content.len() as u64);
495495
header.set_mode(0o644);
496+
// uid/gid must be set or a root-side ownership-preserving extraction
497+
// can't parse the (blank) uid field. Real OCI layers always set them.
498+
header.set_uid(0);
499+
header.set_gid(0);
496500
header.set_cksum();
497501

498502
builder.append_data(&mut header, filename, content).unwrap();

0 commit comments

Comments
 (0)