From 675a7d77249fafb8ba7621c59fb1b2dcb0620dfd Mon Sep 17 00:00:00 2001 From: Afloat Date: Wed, 11 Nov 2026 03:40:34 +0800 Subject: [PATCH] Recognize required volatile modifiers in CLI signatures (R3.12) (#1580) The .NET signature reader called a type volatile when any of its first eight custom modifiers contained IsVolatile, so optional modifiers, a Custom.IsVolatile type and IsVolatileExtra all counted, and a real required marker after eight other modifiers was missed. A type is now volatile only when a required modifier is exactly System.Runtime.CompilerServices.IsVolatile, checked across every modifier. --- crates/formats/src/dotnet/sig.rs | 14 +-- .../tests/dotnet_volatile_modifiers.rs | 118 ++++++++++++++++++ docs/ROADMAP.md | 2 + docs/STATUS.md | 1 + 4 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 crates/formats/tests/dotnet_volatile_modifiers.rs diff --git a/crates/formats/src/dotnet/sig.rs b/crates/formats/src/dotnet/sig.rs index 0a9fdc231..1ac3a29d1 100644 --- a/crates/formats/src/dotnet/sig.rs +++ b/crates/formats/src/dotnet/sig.rs @@ -275,16 +275,14 @@ impl<'m, 'a> Names<'m, 'a> { Some(self.type_name(table, v >> 2, g, depth)) } - fn skip_mods(&self, c: &mut Cur<'_>, g: &GenCtx<'_>, depth: u32) -> Option> { - let mut mods = Vec::new(); + fn skip_mods(&self, c: &mut Cur<'_>, g: &GenCtx<'_>, depth: u32) -> Option { + let mut is_volatile = false; while matches!(c.peek(), Some(0x1f | 0x20)) { let req = c.u8()? == 0x1f; let m = self.tdor_encoded(c, g, depth, true)?; - if mods.len() < 8 { - mods.push(format!("{}({m})", if req { "modreq" } else { "modopt" })); - } + is_volatile |= req && m == "System.Runtime.CompilerServices.IsVolatile"; } - Some(mods) + Some(is_volatile) } /// One type from a signature. @@ -292,7 +290,7 @@ impl<'m, 'a> Names<'m, 'a> { if depth > MAX_DEPTH { return None; } - let mods = self.skip_mods(c, g, depth)?; + let is_volatile = self.skip_mods(c, g, depth)?; let b = c.u8()?; let s = match b { 0x01 => "void".into(), @@ -382,7 +380,7 @@ impl<'m, 'a> Names<'m, 'a> { 0x45 => format!("pinned {}", self.ty(c, g, depth + 1)?), _ => return None, }; - Some(if mods.iter().any(|m| m.contains("IsVolatile")) { format!("volatile {s}") } else { s }) + Some(if is_volatile { format!("volatile {s}") } else { s }) } fn method_sig_inner(&self, c: &mut Cur<'_>, g: &GenCtx<'_>, depth: u32) -> Option { diff --git a/crates/formats/tests/dotnet_volatile_modifiers.rs b/crates/formats/tests/dotnet_volatile_modifiers.rs new file mode 100644 index 000000000..017eca89b --- /dev/null +++ b/crates/formats/tests/dotnet_volatile_modifiers.rs @@ -0,0 +1,118 @@ +use craft_anything_formats::dotnet::{meta::Metadata, meta::t, sig::GenCtx, sig::Names}; + +fn text(heap: &mut Vec, value: &str) -> u16 { + let offset = heap.len() as u16; + heap.extend_from_slice(value.as_bytes()); + heap.push(0); + offset +} + +fn metadata() -> Vec { + let mut strings = vec![0]; + let mut rows = Vec::new(); + for (name, namespace) in [ + ("IsVolatile", "System.Runtime.CompilerServices"), + ("IsVolatile", "Custom"), + ("IsVolatileExtra", "System.Runtime.CompilerServices"), + ("Marker", "Custom"), + ] { + let name = text(&mut strings, name); + let namespace = text(&mut strings, namespace); + for cell in [0u16, name, namespace] { + rows.extend_from_slice(&cell.to_le_bytes()); + } + } + let mut tables = vec![0, 0, 0, 0, 2, 0, 0, 1]; + tables.extend_from_slice(&(1u64 << t::TYPE_REF).to_le_bytes()); + tables.extend_from_slice(&0u64.to_le_bytes()); + tables.extend_from_slice(&4u32.to_le_bytes()); + tables.extend_from_slice(&rows); + let streams = [("#~", tables.as_slice()), ("#Strings", strings.as_slice()), ("#Blob", &[0][..])]; + let mut out = Vec::from(&b"BSJB\x01\0\x01\0\0\0\0\0\x04\0\0\0v4\0\0\0\0\x03\0"[..]); + let mut offset = out.len() + streams.iter().map(|(name, _)| 8 + (name.len() + 1).div_ceil(4) * 4).sum::(); + for (name, bytes) in streams { + out.extend_from_slice(&(offset as u32).to_le_bytes()); + out.extend_from_slice(&(bytes.len() as u32).to_le_bytes()); + out.extend_from_slice(name.as_bytes()); + out.push(0); + out.resize(out.len().div_ceil(4) * 4, 0); + offset += bytes.len(); + } + for (_, bytes) in streams { + out.extend_from_slice(bytes); + } + out +} + +#[test] +fn an_optional_marker_does_not_imply_volatile() { + let bytes = metadata(); + let md = Metadata::parse(&bytes).unwrap(); + assert!(md.warnings.is_empty(), "{:?}", md.warnings); + let names = Names::new(&md); + let g = GenCtx::default(); + assert_eq!(names.field_sig(&[6, 0x20, 5, 8], &g).as_deref(), Some("int")); + let method = names.method_sig(&[0, 1, 0x1f, 5, 8, 0x20, 5, 8], &g).unwrap(); + assert_eq!(method.return_type, "volatile int"); + assert_eq!(method.params, ["int"]); +} + +#[test] +fn the_marker_requires_the_exact_qualified_name() { + let bytes = metadata(); + let md = Metadata::parse(&bytes).unwrap(); + let names = Names::new(&md); + for reference in [9, 13] { + assert_eq!(names.field_sig(&[6, 0x1f, reference, 8], &GenCtx::default()).as_deref(), Some("int")); + } +} + +#[test] +fn required_markers_after_many_other_modifiers_are_not_lost() { + let bytes = metadata(); + let md = Metadata::parse(&bytes).unwrap(); + let names = Names::new(&md); + for count in [8, 32] { + let mut signature = vec![6]; + for _ in 0..count { + signature.extend_from_slice(&[0x20, 17]); + } + signature.extend_from_slice(&[0x1f, 5, 8]); + assert_eq!(names.field_sig(&signature, &GenCtx::default()).as_deref(), Some("volatile int")); + } +} + +#[test] +fn required_markers_remain_supported_in_nested_types() { + let bytes = metadata(); + let md = Metadata::parse(&bytes).unwrap(); + let names = Names::new(&md); + let g = GenCtx::default(); + assert_eq!(names.field_sig(&[6, 0x1f, 5, 8], &g).as_deref(), Some("volatile int")); + assert_eq!(names.field_sig(&[6, 0x0f, 0x1f, 5, 8], &g).as_deref(), Some("volatile int*")); + assert_eq!(names.field_sig(&[6, 0x1d, 0x1f, 5, 8], &g).as_deref(), Some("volatile int[]")); +} + +#[test] +fn ordinary_types_and_unrelated_modifiers_stay_unchanged() { + let bytes = metadata(); + let md = Metadata::parse(&bytes).unwrap(); + let names = Names::new(&md); + let g = GenCtx::default(); + assert_eq!(names.field_sig(&[6, 8], &g).as_deref(), Some("int")); + for kind in [0x1f, 0x20] { + assert_eq!(names.field_sig(&[6, kind, 17, 8], &g).as_deref(), Some("int")); + } +} + +#[test] +fn a_recognized_marker_does_not_hide_a_malformed_modifier_tail() { + let bytes = metadata(); + let md = Metadata::parse(&bytes).unwrap(); + let names = Names::new(&md); + for tail in [&[0x20][..], &[0x20, 0x80], &[0x20, 3, 8], &[]] { + let mut signature = vec![6, 0x1f, 5]; + signature.extend_from_slice(tail); + assert_eq!(names.field_sig(&signature, &GenCtx::default()), None); + } +} diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index bcdc085ba..33734ecc1 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -1996,6 +1996,8 @@ Owner: open · Status: in progress — claimed: Afloat16, branch bugfix/r3.12-wasm-function-count - [x] Reject TypeSpec handles where CLI class/value-type and generic signatures require TypeDef or TypeRef, while retaining standalone TypeSpec and custom-modifier decoding. — claimed: Afloat16, branch bugfix/r3.12-dotnet-signature-type-handles-20261110 +- [x] Recognize volatile type notation from required `System.Runtime.CompilerServices.IsVolatile` modifiers across the complete modifier list. + — claimed: Afloat16, branch bugfix/r3.12-dotnet-volatile-modifiers-20261110 - [x] Preserve complete Unicode characters in shortened .NET strings. — claimed: Afloat16, branch bugfix/r3.12-dotnet-user-string-surrogate-limit-20261105 - [x] Validate CIL method exception-section kinds, extents and complete clause records before reading exception handlers. diff --git a/docs/STATUS.md b/docs/STATUS.md index f3dea4bee..c9a6186b5 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -29,6 +29,7 @@ coverage and secrets passed. The companion CLI was built with locked dependencie | Area | State | Verified by | |---|---|---| | CLI signature type handles | CLASS, VALUETYPE and generic constructors accept TypeDef/TypeRef handles rather than expanding nested TypeSpec signatures; standalone TypeSpec and custom modifiers remain supported. | Four focused groups cover direct and nested invalid handles, legitimate generic types and custom modifiers. The separate recursive fixture times out on the original parser and completes under the same 128 MiB / two-second process limits after the correction. | +| CLI volatile modifiers | Type notation recognizes required `System.Runtime.CompilerServices.IsVolatile` modifiers by their complete qualified name, throughout the modifier list. Optional modifiers and similarly named types do not imply volatile. | Six regression groups cover optional and required markers, namespace/name lookalikes, late markers, method and nested signatures, ordinary types and malformed tails after a valid marker. | | Objective-C registration identity | Classes and categories listed by both ordinary and non-lazy tables appear once per decoded address, in first-seen order. Distinct definitions with the same name remain separate. | Three original Mach-O regressions fail before the correction; class/category overlap, chained-pointer aliases and same-named distinct definitions pass afterward, with an ordinary class/protocol control. No Objective-C runtime was executed. | | PyInstaller archives | CArchive members cannot read the table, cookie or appended signing data. Legacy PYZ data members unpack with their original bytes and names. Empty namespace packages are listed as metadata; older namespaces with code still unpack as packages. | CArchive range fixtures cover both cookies, cross-boundary members, signed tails and empty options; PYZ fixtures cover mixed member types. Verified source `a5bcfaed`: [formats tests, fmt and clippy](https://github.com/Afloat16/claude-mem/actions/runs/42636776430/job/129226891917); [layers, locks, secrets, wasm and unchanged Cargo.lock](https://github.com/Afloat16/claude-mem/actions/runs/42640688213/job/129240669663); [unchanged-code regression failures](https://github.com/Afloat16/claude-mem/actions/runs/42636776430/job/129226895582). | | Expanded PYZ paths | Nested module, resource and unknown-member paths share an 8 MiB retained-byte budget with namespace names across one listing. Complete identities and declared module counts remain available in partial results. | Shared-prefix, multiple-PYZ, Unicode namespace and normal extraction regressions. A native PyInstaller 6.16.0 archive writer produced a 5.04 MB CArchive whose unbounded listing retained 146 MB of path text and aborted under a 128 MiB address-space limit. The bounded reader completes under that limit, retaining 8,386,347 expanded-path bytes plus the existing 3,626-byte outer member name, with truncation reported. |