mirror of
https://github.com/storytold/craft-anything.git
synced 2026-11-20 22:40:55 +01:00
Apply global PAX attributes to TAR members (R3.12) (#1570)
The tar reader handled per-member PAX extensions but ignored global ones, so later members could get the wrong path, link target or stored size, and a global size override left the next header at the wrong offset. Global path, link and size attributes are now kept until a later global record replaces or deletes them, applied after per-member PAX values and before GNU long names or the plain header. Each metadata header is read at its own stored length, inherited sizes must be unsigned decimals, and inherited sparse attributes are reported as unsupported. Copies of inherited names share a 64 MiB budget; engine installs refuse an archive that exceeds it before writing anything.
This commit is contained in:
1 parent
1fc942a04f
commit
ffaef8564d
5 files changed
+331
-18
No files matched your search
@@ -396,6 +396,9 @@ fn unpack_tar(data: &[u8], dest: &Path, strip_prefix: Option<&str>, cancel: Opti
|
||||
let (code, message) = match reason {
|
||||
StopReason::GnuMetadataTooLong => (ErrorCode::OverLimit, "A GNU tar name or link exceeds the supported limit; the archive was not unpacked."),
|
||||
StopReason::GnuMetadataTruncated => (ErrorCode::GarbledOutput, "The tar archive ends inside a GNU name or link record; it was not unpacked."),
|
||||
StopReason::GlobalNameBudget => {
|
||||
(ErrorCode::OverLimit, "The tar archive's inherited PAX names exceed the retained-name limit; it was not unpacked.")
|
||||
}
|
||||
};
|
||||
return Err(ToolError::new(code, message).with_remediation("Use a complete archive with supported member names, or install this engine by hand."));
|
||||
}
|
||||
@@ -460,6 +463,24 @@ fn set_executable(_path: &Path) {}
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn global_pax_name_copy_limit_refuses_installation_before_writes() {
|
||||
use craft_anything_testkit::firmware as fx;
|
||||
let global = format!("4107 path={}\n", "n".repeat(4096));
|
||||
assert_eq!(global.len(), 4107);
|
||||
let mut entries = vec![("pkg/bin/tool", b'0', b"replacement".as_slice(), ""), ("global", b'g', global.as_bytes(), "")];
|
||||
entries.extend(std::iter::repeat_n(("ignored", b'0', b"".as_slice(), ""), 16_385));
|
||||
let data = fx::tar_entries(&entries);
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
std::fs::create_dir(dir.path().join("bin")).unwrap();
|
||||
let installed = dir.path().join("bin/tool");
|
||||
std::fs::write(&installed, b"installed").unwrap();
|
||||
let error = unpack_tar(&data, dir.path(), Some("pkg/"), None, &|_| {}).unwrap_err();
|
||||
assert_eq!(error.code, ErrorCode::OverLimit);
|
||||
assert!(error.message.contains("inherited PAX names"));
|
||||
assert_eq!(std::fs::read(installed).unwrap(), b"installed");
|
||||
}
|
||||
|
||||
fn assert_gnu_metadata_refused_before_writes(kind: u8, cut_short: bool, expected: ErrorCode) {
|
||||
use craft_anything_testkit::firmware as fx;
|
||||
let long = vec![b'n'; 4097];
|
||||
|
||||
+123
-18
@@ -1,9 +1,10 @@
|
||||
//! Member walkers for Unix archives: tar (v7, ustar, GNU long names and base-256 sizes, pax path
|
||||
//! overrides) and cpio (newc, crc and portable odc). They list members and where their data
|
||||
//! local/global overrides) and cpio (newc, crc and portable odc). They list members and where their data
|
||||
//! lies; nothing is extracted here, and no input can make them panic or loop forever.
|
||||
|
||||
use crate::bytes::Reader;
|
||||
use serde::Serialize;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
/// What a member is.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
|
||||
@@ -31,12 +32,13 @@ pub struct Member {
|
||||
pub mode: u32,
|
||||
}
|
||||
|
||||
/// Why GNU tar name metadata stopped a walk that still retains earlier members.
|
||||
/// Why tar name metadata stopped a walk that still retains earlier members.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum StopReason {
|
||||
GnuMetadataTooLong,
|
||||
GnuMetadataTruncated,
|
||||
GlobalNameBudget,
|
||||
}
|
||||
|
||||
/// The members of an archive.
|
||||
@@ -51,7 +53,7 @@ pub struct Listing {
|
||||
pub complete: bool,
|
||||
/// True when `max_members` stopped the walk.
|
||||
pub truncated: bool,
|
||||
/// GNU metadata that prevented reading the remaining member identities.
|
||||
/// Name metadata that prevented reading the remaining member identities.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub stop_reason: Option<StopReason>,
|
||||
pub warnings: Vec<String>,
|
||||
@@ -59,6 +61,7 @@ pub struct Listing {
|
||||
|
||||
const BLOCK: usize = 512;
|
||||
const MAX_NAME: usize = 4096;
|
||||
const MAX_GLOBAL_NAME_COPIES: usize = 64 << 20;
|
||||
|
||||
fn trim_field(f: &[u8]) -> &[u8] {
|
||||
let end = f.iter().position(|&b| b == 0).unwrap_or(f.len());
|
||||
@@ -118,6 +121,10 @@ fn round_up(v: u64, to: u64) -> Option<u64> {
|
||||
|
||||
/// Walk a tar archive. `None` when the first block is not a valid header.
|
||||
pub fn tar(data: &[u8], max_members: usize) -> Option<Listing> {
|
||||
tar_with_name_copy_limit(data, max_members, MAX_GLOBAL_NAME_COPIES)
|
||||
}
|
||||
|
||||
fn tar_with_name_copy_limit(data: &[u8], max_members: usize, mut name_bytes_left: usize) -> Option<Listing> {
|
||||
let r = Reader::new(data);
|
||||
if !tar_header_ok(r.slice(0, BLOCK)?) {
|
||||
return None;
|
||||
@@ -130,6 +137,11 @@ pub fn tar(data: &[u8], max_members: usize) -> Option<Listing> {
|
||||
let mut pax_link: Option<String> = None;
|
||||
let mut pax_size: Option<u64> = None;
|
||||
let mut pax_sparse = false;
|
||||
let mut global_path: Option<String> = None;
|
||||
let mut global_link: Option<String> = None;
|
||||
let mut global_size: Option<u64> = None;
|
||||
// Borrow keys from the input: global sparse attributes persist until their own deletion.
|
||||
let mut global_sparse: BTreeSet<&[u8]> = BTreeSet::new();
|
||||
// Every iteration advances by at least one block, so the walk is bounded by the input size.
|
||||
'headers: loop {
|
||||
let Some(h) = r.slice(pos, BLOCK) else {
|
||||
@@ -156,7 +168,7 @@ pub fn tar(data: &[u8], max_members: usize) -> Option<Listing> {
|
||||
break;
|
||||
};
|
||||
if !matches!(typeflag, b'x' | b'g' | b'L' | b'K')
|
||||
&& let Some(s) = pax_size.take()
|
||||
&& let Some(s) = pax_size.take().or(global_size)
|
||||
{
|
||||
size = s;
|
||||
}
|
||||
@@ -192,7 +204,8 @@ pub fn tar(data: &[u8], max_members: usize) -> Option<Listing> {
|
||||
long_link = value;
|
||||
}
|
||||
}
|
||||
b'x' => {
|
||||
b'x' | b'g' => {
|
||||
let global = typeflag == b'g';
|
||||
if let Some(mut remaining) = body {
|
||||
for _ in 0..256 {
|
||||
if remaining.is_empty() {
|
||||
@@ -204,7 +217,15 @@ pub fn tar(data: &[u8], max_members: usize) -> Option<Listing> {
|
||||
break 'headers;
|
||||
};
|
||||
if key.starts_with(b"GNU.sparse.") {
|
||||
pax_sparse = true;
|
||||
if global {
|
||||
if value.is_empty() {
|
||||
global_sparse.remove(key);
|
||||
} else {
|
||||
global_sparse.insert(key);
|
||||
}
|
||||
} else {
|
||||
pax_sparse = true;
|
||||
}
|
||||
}
|
||||
match key {
|
||||
b"path" | b"linkpath" | b"GNU.sparse.name" => {
|
||||
@@ -213,10 +234,27 @@ pub fn tar(data: &[u8], max_members: usize) -> Option<Listing> {
|
||||
out.length = pos as u64;
|
||||
break 'headers;
|
||||
}
|
||||
let slot = if key == b"linkpath" { &mut pax_link } else { &mut pax_path };
|
||||
*slot = Some(String::from_utf8_lossy(value).into_owned());
|
||||
let slot = match (global, key == b"linkpath") {
|
||||
(true, true) => &mut global_link,
|
||||
(true, false) => &mut global_path,
|
||||
(false, true) => &mut pax_link,
|
||||
(false, false) => &mut pax_path,
|
||||
};
|
||||
*slot = if global && value.is_empty() { None } else { Some(String::from_utf8_lossy(value).into_owned()) };
|
||||
}
|
||||
b"size" => {
|
||||
let size = std::str::from_utf8(value).ok().and_then(|s| s.parse().ok());
|
||||
if global {
|
||||
if !value.is_empty() && (size.is_none() || !value.iter().all(u8::is_ascii_digit)) {
|
||||
out.warnings.push(format!("invalid global pax size at {pos:#x}"));
|
||||
out.length = pos as u64;
|
||||
break 'headers;
|
||||
}
|
||||
global_size = size;
|
||||
} else {
|
||||
pax_size = size;
|
||||
}
|
||||
}
|
||||
b"size" => pax_size = std::str::from_utf8(value).ok().and_then(|s| s.parse().ok()),
|
||||
_ => {}
|
||||
}
|
||||
remaining = rest;
|
||||
@@ -228,15 +266,38 @@ pub fn tar(data: &[u8], max_members: usize) -> Option<Listing> {
|
||||
}
|
||||
}
|
||||
}
|
||||
b'g' => {}
|
||||
_ => {
|
||||
if out.members.len() >= max_members {
|
||||
out.truncated = true;
|
||||
out.length = pos as u64;
|
||||
break;
|
||||
}
|
||||
let linked = matches!(typeflag, b'1' | b'2');
|
||||
let copied_path = if pax_path.is_none() { global_path.as_ref().map_or(0, String::len) } else { 0 };
|
||||
let copied_link = if linked && pax_link.is_none() { global_link.as_ref().map_or(0, String::len) } else { 0 };
|
||||
let Some(remaining) = name_bytes_left.checked_sub(copied_path.saturating_add(copied_link)) else {
|
||||
out.stop_reason = Some(StopReason::GlobalNameBudget);
|
||||
out.warnings.push("the retained global pax name-byte budget was reached; later members were omitted".into());
|
||||
out.length = pos as u64;
|
||||
break;
|
||||
};
|
||||
name_bytes_left = remaining;
|
||||
// Old GNU headers use these bytes for timestamps and sparse-file metadata.
|
||||
let ustar = h.get(257..263) == Some(b"ustar\0");
|
||||
let base = text(h.get(0..100).unwrap_or(&[]));
|
||||
let prefix = if ustar { text(h.get(345..500).unwrap_or(&[])) } else { String::new() };
|
||||
let joined = if prefix.is_empty() { base } else { format!("{prefix}/{base}") };
|
||||
let name = pax_path.take().or(long_name.take()).unwrap_or(joined);
|
||||
let link = pax_link.take().or(long_link.take()).or_else(|| Some(text(h.get(157..257).unwrap_or(&[])))).filter(|l| !l.is_empty());
|
||||
// PAX values override header names, including GNU's long-name replacement.
|
||||
// Consume the one-member GNU records even when a PAX value takes precedence.
|
||||
let gnu_name = long_name.take();
|
||||
let gnu_link = long_link.take();
|
||||
let name = pax_path.take().or_else(|| global_path.clone()).or(gnu_name).unwrap_or(joined);
|
||||
let link = pax_link
|
||||
.take()
|
||||
.or_else(|| if linked { global_link.clone() } else { None })
|
||||
.or(gnu_link)
|
||||
.or_else(|| Some(text(h.get(157..257).unwrap_or(&[]))))
|
||||
.filter(|l| !l.is_empty());
|
||||
let mut kind = match typeflag {
|
||||
b'0' | 0 | b'7' => {
|
||||
if name.ends_with('/') {
|
||||
@@ -252,7 +313,7 @@ pub fn tar(data: &[u8], max_members: usize) -> Option<Listing> {
|
||||
b'6' => MemberKind::Fifo,
|
||||
_ => MemberKind::Other,
|
||||
};
|
||||
if std::mem::take(&mut pax_sparse) {
|
||||
if std::mem::take(&mut pax_sparse) || !global_sparse.is_empty() {
|
||||
kind = MemberKind::Other;
|
||||
out.warnings.push(format!("{name}: GNU sparse reconstruction is unsupported; stored extents are not the complete file"));
|
||||
}
|
||||
@@ -260,11 +321,6 @@ pub fn tar(data: &[u8], max_members: usize) -> Option<Listing> {
|
||||
if body.is_none() && kind == MemberKind::File {
|
||||
out.warnings.push(format!("{name}: data runs past the end of the input"));
|
||||
}
|
||||
if out.members.len() >= max_members {
|
||||
out.truncated = true;
|
||||
out.length = pos as u64;
|
||||
break;
|
||||
}
|
||||
out.members.push(Member {
|
||||
name,
|
||||
kind,
|
||||
@@ -482,6 +538,55 @@ mod tests {
|
||||
use super::*;
|
||||
use craft_anything_testkit::firmware as fx;
|
||||
|
||||
fn global_record(key: &str, value: &str) -> String {
|
||||
let tail = format!(" {key}={value}\n");
|
||||
let mut len = tail.len() + 1;
|
||||
loop {
|
||||
let record = format!("{len}{tail}");
|
||||
if record.len() == len {
|
||||
return record;
|
||||
}
|
||||
len = record.len();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn global_name_copies_stop_before_spending_the_budget() {
|
||||
let global = global_record("path", "shared");
|
||||
let data = fx::tar_entries(&[("global", b'g', global.as_bytes(), ""), ("one", b'0', b"", ""), ("two", b'0', b"", ""), ("three", b'0', b"", "")]);
|
||||
let listing = tar_with_name_copy_limit(&data, 10, 12).unwrap();
|
||||
assert_eq!(listing.members.len(), 2);
|
||||
assert!(listing.members.iter().all(|m| m.name == "shared"));
|
||||
assert_eq!(listing.stop_reason, Some(StopReason::GlobalNameBudget));
|
||||
assert!(!listing.complete && !listing.truncated);
|
||||
assert!(listing.warnings.iter().any(|w| w.contains("name-byte budget")));
|
||||
assert_eq!(listing.length, 2048);
|
||||
assert!(tar_with_name_copy_limit(&data, 10, 18).unwrap().complete);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_names_and_unused_global_links_do_not_spend_copy_bytes() {
|
||||
let global = global_record("path", "name") + &global_record("linkpath", "unused-link");
|
||||
let local = global_record("path", "local-name");
|
||||
let data =
|
||||
fx::tar_entries(&[("global", b'g', global.as_bytes(), ""), ("local", b'x', local.as_bytes(), ""), ("one", b'0', b"", ""), ("two", b'0', b"", "")]);
|
||||
let listing = tar_with_name_copy_limit(&data, 10, 4).unwrap();
|
||||
assert!(listing.complete);
|
||||
assert_eq!(listing.members.iter().map(|m| m.name.as_str()).collect::<Vec<_>>(), ["local-name", "name"]);
|
||||
assert!(listing.members.iter().all(|m| m.link_target.is_none()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn global_names_and_links_share_the_decoded_byte_budget() {
|
||||
let global = global_record("path", "é") + &global_record("linkpath", "中");
|
||||
let data = fx::tar_entries(&[("global", b'g', global.as_bytes(), ""), ("one", b'2', b"", "fallback"), ("two", b'1', b"", "fallback")]);
|
||||
let listing = tar_with_name_copy_limit(&data, 10, 5).unwrap();
|
||||
assert_eq!(listing.members.len(), 1);
|
||||
assert_eq!(listing.members[0].link_target.as_deref(), Some("中"));
|
||||
assert_eq!(listing.stop_reason, Some(StopReason::GlobalNameBudget));
|
||||
assert!(tar_with_name_copy_limit(&data, 10, 10).unwrap().complete);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oversized_gnu_names_do_not_alias_their_truncated_prefix() {
|
||||
for kind in *b"LK" {
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
use craft_anything_formats::tarcpio::{MemberKind, member_data, tar};
|
||||
use craft_anything_testkit::firmware as fx;
|
||||
|
||||
fn record(key: &str, value: &str) -> String {
|
||||
let tail = format!(" {key}={value}\n");
|
||||
let mut len = tail.len() + 1;
|
||||
loop {
|
||||
let record = format!("{len}{tail}");
|
||||
if record.len() == len {
|
||||
return record;
|
||||
}
|
||||
len = record.len();
|
||||
}
|
||||
}
|
||||
|
||||
fn clear_size(data: &mut [u8], at: usize) {
|
||||
let header = &mut data[at..at + 512];
|
||||
header[124..136].copy_from_slice(b"00000000000\0");
|
||||
header[148..156].fill(b' ');
|
||||
let sum: u32 = header.iter().map(|&b| u32::from(b)).sum();
|
||||
header[148..156].copy_from_slice(format!("{sum:06o}\0 ").as_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn global_path_and_size_persist_across_members_and_metadata() {
|
||||
let global = record("path", "global-name") + &record("size", "3");
|
||||
let local = record("comment", "unrelated");
|
||||
let mut data = fx::tar_entries(&[
|
||||
("global", b'g', global.as_bytes(), ""),
|
||||
("first", b'0', b"abc", ""),
|
||||
("metadata", b'x', local.as_bytes(), ""),
|
||||
("second", b'0', b"def", ""),
|
||||
]);
|
||||
clear_size(&mut data, 1024);
|
||||
clear_size(&mut data, 3072);
|
||||
let listing = tar(&data, 10).unwrap();
|
||||
assert!(listing.complete, "{:?}", listing.warnings);
|
||||
assert_eq!(listing.members.len(), 2);
|
||||
assert!(listing.members.iter().all(|member| member.name == "global-name" && member.size == 3));
|
||||
assert_eq!(member_data(&data, &listing.members[0]), Some(b"abc".as_slice()));
|
||||
assert_eq!(member_data(&data, &listing.members[1]), Some(b"def".as_slice()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_attributes_override_only_one_member() {
|
||||
let global = record("path", "inherited") + &record("size", "3");
|
||||
let local = record("path", "one-member") + &record("size", "0");
|
||||
let data = fx::tar_entries(&[
|
||||
("global", b'g', global.as_bytes(), ""),
|
||||
("local", b'x', local.as_bytes(), ""),
|
||||
("first", b'0', b"", ""),
|
||||
("second", b'0', b"abc", ""),
|
||||
]);
|
||||
let listing = tar(&data, 10).unwrap();
|
||||
assert!(listing.complete);
|
||||
assert_eq!(listing.members.iter().map(|m| (m.name.as_str(), m.size)).collect::<Vec<_>>(), [("one-member", 0), ("inherited", 3)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn later_global_records_update_and_delete_only_their_keys() {
|
||||
let first = record("path", "first-global") + &record("size", "3");
|
||||
let second = record("path", "second-global");
|
||||
let remove = record("path", "") + &record("size", "");
|
||||
let data = fx::tar_entries(&[
|
||||
("global", b'g', first.as_bytes(), ""),
|
||||
("one", b'0', b"abc", ""),
|
||||
("global", b'g', second.as_bytes(), ""),
|
||||
("two", b'0', b"def", ""),
|
||||
("global", b'g', remove.as_bytes(), ""),
|
||||
("plain", b'0', b"normal", ""),
|
||||
]);
|
||||
let listing = tar(&data, 10).unwrap();
|
||||
assert!(listing.complete);
|
||||
assert_eq!(listing.members.iter().map(|m| (m.name.as_str(), m.size)).collect::<Vec<_>>(), [("first-global", 3), ("second-global", 3), ("plain", 6)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn global_link_names_persist_until_deleted() {
|
||||
let global = record("linkpath", "shared-target");
|
||||
let local = record("linkpath", "local-target");
|
||||
let remove = record("linkpath", "");
|
||||
let data = fx::tar_entries(&[
|
||||
("global", b'g', global.as_bytes(), ""),
|
||||
("one", b'2', b"", "fallback"),
|
||||
("local", b'x', local.as_bytes(), ""),
|
||||
("two", b'1', b"", "fallback"),
|
||||
("three", b'2', b"", "fallback"),
|
||||
("global", b'g', remove.as_bytes(), ""),
|
||||
("four", b'2', b"", "original"),
|
||||
]);
|
||||
let listing = tar(&data, 10).unwrap();
|
||||
assert!(listing.complete);
|
||||
assert_eq!(
|
||||
listing.members.iter().map(|m| m.link_target.as_deref()).collect::<Vec<_>>(),
|
||||
[Some("shared-target"), Some("local-target"), Some("shared-target"), Some("original")]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn malformed_or_excess_global_records_do_not_claim_complete_members() {
|
||||
for metadata in [String::from("10 size=3!"), record("comment", "").repeat(257), record("path", &"a".repeat(4097))] {
|
||||
let data = fx::tar_entries(&[("keep", b'0', b"ok", ""), ("global", b'g', metadata.as_bytes(), ""), ("after", b'0', b"later", "")]);
|
||||
let listing = tar(&data, 10).unwrap();
|
||||
assert!(!listing.complete);
|
||||
assert_eq!(listing.members.len(), 1);
|
||||
assert_eq!(listing.members[0].name, "keep");
|
||||
assert!(listing.warnings.iter().any(|warning| warning.contains("pax")));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn global_sparse_metadata_keeps_stored_extents_out_of_regular_files() {
|
||||
let global = record("GNU.sparse.map", "0,3");
|
||||
let remove = record("GNU.sparse.map", "");
|
||||
let data = fx::tar_entries(&[
|
||||
("global", b'g', global.as_bytes(), ""),
|
||||
("one", b'0', b"abc", ""),
|
||||
("two", b'0', b"def", ""),
|
||||
("global", b'g', remove.as_bytes(), ""),
|
||||
("plain", b'0', b"ghi", ""),
|
||||
]);
|
||||
let listing = tar(&data, 10).unwrap();
|
||||
assert!(listing.complete);
|
||||
assert_eq!(listing.members.iter().map(|m| m.kind).collect::<Vec<_>>(), [MemberKind::Other, MemberKind::Other, MemberKind::File]);
|
||||
assert_eq!(listing.warnings.iter().filter(|warning| warning.contains("sparse")).count(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unrelated_global_fields_preserve_local_and_gnu_names() {
|
||||
let global = record("comment", "not a member name");
|
||||
let local = record("path", "local");
|
||||
let data = fx::tar_entries(&[
|
||||
("local", b'x', local.as_bytes(), ""),
|
||||
("global", b'g', global.as_bytes(), ""),
|
||||
("first", b'0', b"one", ""),
|
||||
("././@LongLink", b'L', b"gnu-name\0", ""),
|
||||
("second", b'0', b"two", ""),
|
||||
]);
|
||||
let listing = tar(&data, 10).unwrap();
|
||||
assert!(listing.complete && listing.warnings.is_empty());
|
||||
assert_eq!(listing.members.iter().map(|m| m.name.as_str()).collect::<Vec<_>>(), ["local", "gnu-name"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn global_names_obey_the_existing_member_limit() {
|
||||
let path = "a".repeat(4096);
|
||||
let global = record("path", &path);
|
||||
let data = fx::tar_entries(&[("global", b'g', global.as_bytes(), ""), ("one", b'0', b"abc", ""), ("two", b'0', b"def", "")]);
|
||||
let listing = tar(&data, 1).unwrap();
|
||||
assert!(listing.truncated && !listing.complete);
|
||||
assert_eq!(listing.members.len(), 1);
|
||||
assert_eq!(listing.members[0].name, path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn global_pax_names_override_and_consume_gnu_name_records() {
|
||||
let global = record("path", "global") + &record("linkpath", "global-target");
|
||||
let remove = record("path", "") + &record("linkpath", "");
|
||||
let data = fx::tar_entries(&[
|
||||
("global", b'g', global.as_bytes(), ""),
|
||||
("LongLink", b'L', b"gnu-name\0", ""),
|
||||
("LongLink", b'K', b"gnu-target\0", ""),
|
||||
("first", b'2', b"", "fallback"),
|
||||
("global", b'g', remove.as_bytes(), ""),
|
||||
("plain", b'2', b"", "original"),
|
||||
]);
|
||||
let listing = tar(&data, 10).unwrap();
|
||||
assert!(listing.complete);
|
||||
assert_eq!(
|
||||
listing.members.iter().map(|m| (m.name.as_str(), m.link_target.as_deref())).collect::<Vec<_>>(),
|
||||
[("global", Some("global-target")), ("plain", Some("original"))]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nonempty_global_sizes_must_be_unsigned_decimal_numbers() {
|
||||
for size in ["+3", "-3", "3x", " 3", "18446744073709551616"] {
|
||||
let global = record("size", size);
|
||||
let data = fx::tar_entries(&[("keep", b'0', b"abc", ""), ("global", b'g', global.as_bytes(), ""), ("after", b'0', b"def", "")]);
|
||||
let listing = tar(&data, 10).unwrap();
|
||||
assert!(!listing.complete);
|
||||
assert_eq!(listing.members.len(), 1);
|
||||
assert!(listing.warnings.iter().any(|warning| warning.contains("global pax size")));
|
||||
}
|
||||
}
|
||||
@@ -2035,6 +2035,7 @@ Owner: open · Status: in progress
|
||||
The [unchanged-code baseline](https://github.com/Afloat16/claude-mem/actions/runs/42636776430/job/129226895582) reproduces the new regression cases.
|
||||
- [x] Exercise signed PAX lengths, empty keys and equals signs inside a path value.
|
||||
— claimed: Afloat16, branch bugfix/r3.12-pax-record-framing
|
||||
- [x] Apply global PAX archive attributes to later members, honor local overrides and global deletions, and bound inherited name copies before extraction.
|
||||
- [x] Bound and cancel CRC cpio verification across firmware probes, and reject non-hex checksum
|
||||
fields — claimed: Afloat16, branch bugfix/r3.12-bound-cpio-crc-scans-20261103
|
||||
- [x] More parsers keep to the bytes they declare and refuse impossible values: signed LEB128 past
|
||||
|
||||
@@ -80,6 +80,7 @@ coverage and secrets passed. The companion CLI was built with locked dependencie
|
||||
| Unreal DXT3 textures | PF_DXT3 uses the shared bounded texture decoder, preserving explicit four-bit alpha and the four-colour palette even when the first endpoint is smaller. | Synthetic cooked Unreal package and pixel fixtures cover all alpha levels, colour interpolation, clipped edges, mip boundaries, truncated blocks and output budgets. |
|
||||
| Unity RGB9e5 textures | RGB9e5Float textures unpack shared-exponent RGB and use the existing linear-to-sRGB display conversion with opaque alpha and Unity row inversion. | Synthetic serialized Texture2D and pixel fixtures cover shared exponent/channel order, comparison with RGBAFloat, zero and finite maximum encodings, mip length, truncation and output limits. |
|
||||
| Unity RG32, RGB48 and RGBA64 textures | Decode two, three or four unsigned 16-bit channels through the bounded first-mip pipeline, quantizing each channel to RGBA8 with nearest rounding. Missing blue is zero; missing alpha is opaque. | Six synthetic `unity_unorm16_textures` regressions cover names/sizes, unsigned boundaries, little-endian channels, alpha, row inversion, truncated input, output budgets, trailing mips and serialized Texture2D fixtures. |
|
||||
| Global PAX archive attributes | TAR members inherit global paths, link targets and stored sizes until replaced or deleted. Per-member PAX values take precedence; metadata headers keep their own lengths. Global sparse attributes keep unsupported stored extents out of regular files. Global records use the existing framing, name and record limits; a 64 MiB inherited-name copy budget retains a partial inventory and refuses engine installation before writes. | Ten original global/local/deletion/framing/sparse/budget regressions, including nine failures against the unchanged reader, plus three copy-budget controls and an installer preservation regression. Native GNU tar confirms global inheritance, deletion and precedence over GNU long names on generated archives; existing local-empty-value behavior is preserved. |
|
||||
| Unity R16 and RG16 textures | R16 exports unsigned 16-bit samples as normalized grayscale; RG16 exports two eight-bit red/green channels with blue zero and alpha opaque. Both use the existing bounded first-mip pipeline. | Synthetic `unity_integer_textures` regressions (4 tests): Unsigned extrema and quantization boundaries, red/green channel order, Unity row inversion, first-mip length, truncated pixels, zero/huge dimensions and output budgets. [Format checks](https://github.com/Afloat16/claude-mem/actions/runs/42633003467/job/129213811395) and [compatibility gates](https://github.com/Afloat16/claude-mem/actions/runs/42642583301/job/129247271153) passed at `540b4947aa1b`. |
|
||||
| Unity ETC1 textures | ETC_RGB4 decodes individual and differential blocks with both subblock orientations, all modifier tables and Unity row order. Invalid differential base colours are rejected; clipped edges and output budgets use the shared pixel pipeline. | Seven original synthetic cases cover selector planes, all tables, signed deltas, colour clipping, edge blocks, first-mip limits, malformed blocks and a serialized Texture2D object. |
|
||||
| Unity floating-point textures | The PNG exporter reads RHalf, RGHalf, RGBAHalf, RFloat, RGFloat and RGBAFloat. RGB is converted from linear light to 8-bit sRGB, alpha stays linear, and scalar textures are shown in grey. | Synthetic half- and full-precision textures cover every channel layout, short mips, row order, non-finite values and clipping. |
|
||||
|
||||
Reference in new issue
Block a user