Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

fix: phone file names can't point outside the folder on Windows

Bee6a928511fd64
diff --git a/core/nectarlink-core/src/continuity_camera.rs b/core/nectarlink-core/src/continuity_camera.rs
index 7965fc3..01f2f3e 100644
--- a/core/nectarlink-core/src/continuity_camera.rs
+++ b/core/nectarlink-core/src/continuity_camera.rs
@@ -308,7 +308,8 @@ async fn take_result(
CameraCaptureMode::Scan => format!("Scan.{default_ext}"),
};
let raw_name = if meta.file_name.trim().is_empty() { &fallback_name } else { &meta.file_name };
- let safe_name = crate::transfer::safe_file_name(raw_name);
+ // Safe to save on any system: `C:x.jpg` must not become a path on drive C.
+ let safe_name = crate::transfer::storable_name(&crate::transfer::safe_file_name(raw_name));
let saved_path = match tokio::fs::create_dir_all(&shared.downloads_dir).await {
Ok(()) => {
diff --git a/core/nectarlink-core/src/lib.rs b/core/nectarlink-core/src/lib.rs
index 0a99790..2ba1c97 100644
--- a/core/nectarlink-core/src/lib.rs
+++ b/core/nectarlink-core/src/lib.rs
@@ -161,7 +161,7 @@ pub use timeline::{
};
pub use transfer::{
Direction, FileSource, OutgoingFile, RECORDER, RecordingMarker, Transfer, TransferFailure, TransferState,
- outgoing_paths, safe_file_name,
+ outgoing_paths, safe_file_name, storable_name,
};
pub use usb::{DEFAULT_ADB_ADDR, DEFAULT_USB_PORT, USB_PORT_COUNT};
pub use webcam::{TOGGLE as WEBCAM_TOGGLE, WebcamSink};
diff --git a/core/nectarlink-core/src/transfer.rs b/core/nectarlink-core/src/transfer.rs
index 8d82073..ae10c68 100644
--- a/core/nectarlink-core/src/transfer.rs
+++ b/core/nectarlink-core/src/transfer.rs
@@ -223,8 +223,9 @@ fn items(entries: &[FileEntry]) -> Vec<String> {
}
/// A name Windows can store: no reserved device names (`CON`, `COM1`…),
-/// characters it rejects, or trailing dots and spaces.
-pub(crate) fn storable_name(name: &str) -> String {
+/// characters it rejects (including `:`, which would make the name a drive
+/// prefix or an alternate data stream), or trailing dots and spaces.
+pub fn storable_name(name: &str) -> String {
let mut clean: String = name
.chars()
.map(|c| if matches!(c, '<' | '>' | ':' | '"' | '|' | '?' | '*') { '_' } else { c })
diff --git a/core/nectarlink-core/tests/two_devices.rs b/core/nectarlink-core/tests/two_devices.rs
index 62f91f6..e557605 100644
--- a/core/nectarlink-core/tests/two_devices.rs
+++ b/core/nectarlink-core/tests/two_devices.rs
@@ -4180,7 +4180,8 @@ async fn continuity_camera_photo_and_scan_flow() {
let scan_meta = CameraCaptureResultMeta {
request_id: "req-scan-2".into(),
mode: CameraCaptureMode::Scan,
- file_name: "Scan_20260409.jpg".into(),
+ // A drive-prefixed name must still land in the downloads folder.
+ file_name: "C:Scan_20260409.jpg".into(),
mime: "image/jpeg".into(),
size: fake_scan.len() as u64,
width: 1654,
@@ -4221,11 +4222,14 @@ async fn continuity_camera_photo_and_scan_flow() {
.await;
assert_eq!(got_scan_id, "req-scan-2");
assert_eq!(got_scan_mode, CameraCaptureMode::Scan);
- assert_eq!(got_scan_name, "Scan_20260409.jpg");
+ assert_eq!(got_scan_name, "C_Scan_20260409.jpg");
assert_eq!(got_w, 1654);
assert_eq!(got_h, 2339);
assert_eq!(got_scan_data, fake_scan);
- assert!(got_scan_path.unwrap().exists());
+ let got_scan_path = got_scan_path.unwrap();
+ assert!(got_scan_path.exists());
+ assert_eq!(got_scan_path.parent(), path.parent());
+ assert_eq!(got_scan_path.file_name().unwrap(), "C_Scan_20260409.jpg");
pc.node.shutdown().await;
phone.node.shutdown().await;
diff --git a/desktop/app/src/folder_sync.rs b/desktop/app/src/folder_sync.rs
index 2cb5f2a..a2bf3ff 100644
--- a/desktop/app/src/folder_sync.rs
+++ b/desktop/app/src/folder_sync.rs
@@ -269,6 +269,13 @@ fn join_phone_path(folder: &str, rel_path: &str) -> String {
}
}
+/// Whether a phone file can be saved here under the same name. Windows
+/// refuses `:`, reserved names such as `CON`, and trailing dots or spaces, and
+/// `C:x` would even resolve to a path on drive C outside the sync folder.
+fn storable_here(name: &str) -> bool {
+ !cfg!(windows) || nectarlink_core::storable_name(name) == name
+}
+
async fn list_phone_entries(node: &Node, peer: DeviceId, base_folder: &str) -> Option<Vec<SyncEntry>> {
let mut out = Vec::new();
let mut queue = std::collections::VecDeque::new();
@@ -285,6 +292,7 @@ async fn list_phone_entries(node: &Node, peer: DeviceId, base_folder: &str) -> O
if entry.name.starts_with('.')
|| entry.name.ends_with(".nectarlink.part")
|| entry.name.contains(" (conflict-")
+ || !storable_here(&entry.name)
{
continue;
}
@@ -595,6 +603,18 @@ pub fn start_poller() {
mod tests {
use super::*;
+ #[test]
+ #[cfg(windows)]
+ fn phone_names_windows_cannot_store_are_skipped() {
+ assert!(storable_here("IMG_001.jpg"));
+ assert!(storable_here("Trip 2026"));
+ assert!(!storable_here("C:evil.txt"));
+ assert!(!storable_here("notes.txt:stream"));
+ assert!(!storable_here("CON"));
+ assert!(!storable_here("aux.txt"));
+ assert!(!storable_here("trailing."));
+ }
+
#[test]
fn conflict_file_name_inserts_suffix_before_extension() {
assert_eq!(
diff --git a/desktop/app/src/storage.rs b/desktop/app/src/storage.rs
index 836ae68..85f36ef 100644
--- a/desktop/app/src/storage.rs
+++ b/desktop/app/src/storage.rs
@@ -1047,6 +1047,11 @@ mod imp {
let mut missing: Vec<StorageEntry> = Vec::new();
for entry in entries {
+ // Windows can't show a name it can't store (`:`, `CON`, a trailing
+ // dot), and `C:x` would even join to a path outside the folder.
+ if nectarlink_core::storable_name(&entry.name) != entry.name {
+ continue;
+ }
let child_path = local_dir.join(&entry.name);
if !child_path.exists() {
missing.push(entry);