Skip to content

Commit f553893

Browse files
committed
fix(mountinfo): decode a trailing escape and \134 last
`dstack-volume`'s decoder skipped an escape in the last four bytes, so a mount point ending in a space was never matched. The simulator's decoder replaced `\134` first, so a path containing a literal `\040` was decoded twice.
1 parent 9db0b6f commit f553893

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

‎dstack/crates/dstack-volume/src/bin/dstack-volume.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ fn unescape_mountinfo(value: &[u8]) -> Vec<u8> {
415415
let mut decoded = Vec::with_capacity(value.len());
416416
let mut index = 0;
417417
while index < value.len() {
418-
if value[index] == b'\\' && index + 3 < value.len() {
418+
if value[index] == b'\\' && index + 4 <= value.len() {
419419
let octal = &value[index + 1..index + 4];
420420
if octal.iter().all(|byte| matches!(byte, b'0'..=b'7')) {
421421
decoded.push((octal[0] - b'0') * 64 + (octal[1] - b'0') * 8 + (octal[2] - b'0'));
@@ -494,6 +494,7 @@ mod tests {
494494
#[test]
495495
fn decodes_mountinfo_escapes() {
496496
assert_eq!(unescape_mountinfo(b"/run/my\\040volume"), b"/run/my volume");
497+
assert_eq!(unescape_mountinfo(b"/run/trailing\\040"), b"/run/trailing ");
497498
}
498499

499500
#[test]

‎dstack/tee-simulator/src/main.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ fn is_mounted(path: &Path) -> Result<bool> {
132132

133133
fn decode_mountinfo_path(value: &str) -> String {
134134
value
135-
.replace(r"\134", "\\")
136135
.replace(r"\040", " ")
137136
.replace(r"\011", "\t")
138137
.replace(r"\012", "\n")
138+
.replace(r"\134", "\\")
139139
}
140140

141141
fn main() -> Result<()> {

0 commit comments

Comments
 (0)