Skip to content

feat(dvt): relax payload decode, expose launch_with_options, and grow large reads incrementally (F2) - #7

Merged
Derrors merged 2 commits into
masterfrom
feat/dvt-relax-decode-launch-options-growing-reads
Dec 6, 2026
Merged

Derrors merged 2 commits into
masterfrom
feat/dvt-relax-decode-launch-options-growing-reads

Conversation

@Derrors

@Derrors Derrors commented Dec 6, 2026

Copy link
Copy Markdown
Owner

Summary

Three focused DVT & framing improvements for downstream iphone-control (Track F2):

  1. Relax non-framing DVT decode & expose header getters (idevice/src/services/dvt/message.rs, remote_server.rs):

    • Validate header.magic == 0x1F3D_5B79 as a framing error in Message::from_reader.
    • When a well-framed DTX message fails ns_keyed_archive::decode::from_bytes, return Ok(Message) with data: None and raw_data: Some(bytes) (logging via tracing::debug!) instead of tearing down RemoteServerClient's reader loop; likewise yield aux: None when Aux::from_bytes rejects an unknown aux type on a well-framed aux slice.
    • Expose MessageHeader::{identifier, conversation_index, expects_reply} as pub so downstream DTX readers (ictl-ax/src/dtx.rs) can delegate wire framing directly to Message::from_reader.
  2. Public ProcessControlClient::launch_with_options with structured NsErrorInfo (idevice/src/services/dvt/process_control.rs, errors.rs):

    • Remove #[cfg(feature = "xctest")] and make ProcessControlClient::launch_with_options pub; deduplicate launch_app onto launch_with_options.
    • Add DvtError::LaunchFailed(Box<NsErrorInfo>) (sub_code = 6, displaying via NsErrorInfo::fmt), decoding raw_data first via NsErrorInfo::from_archive_bytes (with NsErrorInfo::from_plist fallback), so callers can inspect info.code / info.domain / info.localized_description without hand-rolling processcontrol invocations.
  3. Incremental growing reads instead of upfront 64 MiB allocations (idevice/src/lib.rs, idevice/src/services/dvt/message.rs):

    • Add read_exact_growing (initial reserve capped at 64 KiB + AsyncReadExt::take(len).read_to_end, truncating and returning UnexpectedEof on short reads) and replace upfront vec![0; len] / packet_data.resize(new_total, 0) in Idevice::read_raw, Idevice::read_plist_value, and Message::from_reader.

Tests Added (+8)

  • lib.rs: read_exact_growing_reads_exact_and_avoids_upfront_alloc_on_truncated_frame, read_plist_value_truncation_fails_with_unexpected_eof
  • dvt/message.rs: dvt_from_reader_preserves_raw_data_when_ns_keyed_archive_decode_fails, dvt_from_reader_rejects_bad_magic_and_enforces_total_limit_incrementally, dvt_from_reader_survives_unknown_aux_type_on_well_framed_message
  • dvt/remote_server.rs: reader_survives_undecodable_payload_and_continues_delivering_messages, reader_closes_connection_on_framing_error
  • dvt/process_control.rs: launch_with_options_returns_pid_and_structured_ns_error

Verification

  • cargo fmt --all -- --check: pass
  • cargo test -p idevice --no-default-features --features "ring,dvt" --lib: 25 passed / 0 failed
  • cargo test -p idevice (with full iphone-control feature set): 80 passed / 0 failed (+8)
  • cargo clippy -p idevice --no-default-features --features "ring,full" --all-targets -- -D warnings: pass
  • cargo clippy -p idevice-tools --all-targets -- -D warnings: pass
  • Rust 1.89.0 MSRV cargo check (ring,full and ring,dvt): pass
  • python3 -m unittest discover -s scripts: 5/5 passed
  • python3 scripts/release.py validate: pass

🤖 Generated with Claude Code

Derrors and others added 2 commits December 6, 2026 18:24
… large reads incrementally

Three DVT / transport improvements (Track F2):

1. Relax DVT non-framing decode (dvt/message.rs, dvt/remote_server.rs):
   - Validate DTX header magic (0x1F3D5B79) as a framing error in Message::from_reader.
   - Treat NSKeyedArchive payload decode failure and unknown aux types on
     well-framed messages as non-fatal (data = None while preserving raw_data;
     aux = None on aux decode failure), so RemoteServerClient::spawn_reader
     does not tear down the whole connection when a peer sends an opaque or
     custom-archived payload.
   - Expose MessageHeader::{identifier, conversation_index, expects_reply}
     publicly so callers (e.g. ictl-ax) can reuse Message::from_reader
     directly instead of duplicating DTX wire framing.

2. Expose ProcessControlClient::launch_with_options with structured NsErrorInfo:
   - Make ProcessControlClient::launch_with_options pub (removing the xctest
     feature gate) and deduplicate launch_app onto it.
   - Add DvtError::LaunchFailed(Box<NsErrorInfo>) (sub_code 6) so launch
     failures preserve structured domain/code/description/underlying error
     fields rather than flattening them into IdeviceError::InternalError(String).

3. Incremental growing reads instead of upfront 64 MiB allocations:
   - Add read_exact_growing (capped 64 KiB initial reserve + AsyncReadExt::take
     + read_to_end, truncating on UnexpectedEof) and use it in Idevice::read_raw,
     Idevice::read_plist_value, and DVT Message::from_reader instead of upfront
     vec![0; len] / packet_data.resize(new_total, 0).

Co-Authored-By: Claude Code <noreply@anthropic.com>
Replaced by `NsErrorInfo::from_archive_bytes` in `process_control` with no
remaining callers across the workspace or downstream consumers.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Derrors
Derrors merged commit f908ecd into master Dec 6, 2026
2 checks passed
@Derrors
Derrors deleted the feat/dvt-relax-decode-launch-options-growing-reads branch December 6, 2026 10:39
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.

1 participant