Skip to content

Commit 8d44a7c

Browse files
committed
fix: drop ByteStreamReader::write_to_file
This uses tokio for one (so it's not portable), but also had some security flaws (allowed paths like ../../evil.txt). So, remove it.
1 parent 429de0b commit 8d44a7c

1 file changed

Lines changed: 0 additions & 23 deletions

File tree

livekit-uniffi/src/data_stream/incoming.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::path::PathBuf;
1615
use std::sync::Arc;
1716

1817
use bytes::{Bytes, BytesMut};
@@ -112,28 +111,6 @@ impl ByteStreamReader {
112111
}
113112
Ok(buffer.freeze())
114113
}
115-
116-
/// Streams the contents to a file as chunks arrive, returning the written path.
117-
///
118-
/// `directory` defaults to the system temp dir; `name_override` defaults to the stream name.
119-
pub async fn write_to_file(
120-
&self,
121-
directory: Option<String>,
122-
name_override: Option<String>,
123-
) -> Result<String, DataStreamError> {
124-
use tokio::io::AsyncWriteExt as _;
125-
let directory = directory.map(PathBuf::from).unwrap_or_else(std::env::temp_dir);
126-
let name = name_override.unwrap_or_else(|| self.info.name.clone());
127-
let path = directory.join(name);
128-
129-
let mut reader = self.inner.lock().await;
130-
let mut file = tokio::fs::File::create(&path).await.map_err(ds_api::StreamError::Io)?;
131-
while let Some(chunk) = reader.next().await {
132-
file.write_all(&chunk?).await.map_err(ds_api::StreamError::Io)?;
133-
}
134-
file.flush().await.map_err(ds_api::StreamError::Io)?;
135-
Ok(path.to_string_lossy().into_owned())
136-
}
137114
}
138115

139116
/// Reader for an incoming text data stream.

0 commit comments

Comments
 (0)