The GNU sparse name builder trims trailing slash and /. components before
building the synthetic ustar entry name. If the sparse pathname is fully
pruned, the effective source length becomes zero and build_ustar_entry_name()
reads one byte before the pathname buffer.
Handle the all-pruned pathname case before calling the ustar name builder.
The synthetic name then preserves the root-directory case.
}
/* General case: build a ustar-compatible name adding
- * "/GNUSparseFile/". */
+ * "/GNUSparseFile.0/". */
+
+ if (p == src) {
+ strcpy(dest, "/GNUSparseFile.0/rootdir");
+ return (dest);
+ }
build_ustar_entry_name(dest, src, p - src, "GNUSparseFile.0");
return (dest);