Fix a bug

This commit is contained in:
Igor Katson 2021-07-31 13:13:04 +01:00
parent 175d5c7a97
commit b301b159da
4 changed files with 24 additions and 20 deletions

View file

@ -1,15 +1,19 @@
all: sign-release sign-debug
@PHONY: sign-debug
sign-debug:
codesign -f --entitlements resources/debugging.entitlements -s - target/debug/rqbit
@PHONY: sign-release
sign-release:
codesign -f --entitlements resources/debugging.entitlements -s - target/release/rqbit
@PHONY: build-release
build-release:
cargo build --release
@PHONY: install
install: build-release
$(MAKE) build-release
$(MAKE) sign-release
cp target/release/rqbit "$(HOME)/bin/"
install target/release/rqbit "$(HOME)/bin/"

View file

@ -19,6 +19,7 @@ use parking_lot::Mutex;
use reqwest::Url;
use sha1w::Sha1;
use size_format::SizeFormatterBinary as SF;
use warp::path::full;
use crate::{
chunk_tracker::ChunkTracker,
@ -167,13 +168,10 @@ impl TorrentManager {
for (path_bits, _) in info.iter_filenames_and_lengths()? {
let mut full_path = out.as_ref().to_owned();
for bit in path_bits.iter_components() {
full_path.push(
bit.as_ref()
.map(|b| std::str::from_utf8(b.as_ref()))
.unwrap_or(Ok("output"))?,
);
}
let relative_path = path_bits
.to_pathbuf()
.context("error converting file to path")?;
full_path.push(relative_path);
std::fs::create_dir_all(full_path.parent().unwrap())?;
let file = if options.overwrite {

View file

@ -132,7 +132,7 @@ impl<'a, ByteBuf> FileIteratorName<'a, ByteBuf> {
};
let bit = std::str::from_utf8(part.as_ref())
.context("cannot decode filename bit as UTF-8")?;
if bit.contains("..") {
if bit == ".." {
anyhow::bail!("path traversal detected, \"..\" in filename bit {:?}", bit);
}
if bit.contains(std::path::MAIN_SEPARATOR) {
@ -192,17 +192,7 @@ impl<BufType: AsRef<[u8]>> TorrentMetaV1Info<BufType> {
Ok(single_it.chain(multi_it).flatten())
}
pub fn iter_file_lengths(&self) -> anyhow::Result<impl Iterator<Item = u64> + '_> {
self.is_single_file()?;
let it = std::iter::once(self.length)
.chain(
self.files
.as_deref()
.unwrap_or_default()
.iter()
.map(|f| Some(f.length)),
)
.flatten();
Ok(it)
Ok(self.iter_filenames_and_lengths()?.map(|(_, l)| l))
}
}

View file

@ -321,6 +321,18 @@ async fn main_torrent_info(
};
if opts.list {
for (idx, (filename, len)) in info.iter_filenames_and_lengths()?.enumerate() {
let included = match &only_files {
Some(files) => files.contains(&idx),
None => true,
};
info!(
"File {}, size {}{}",
filename.to_string()?,
SF::new(len),
if included { "" } else { "will skip" }
)
}
info!("--list was passed, nothing to do, exiting.");
return Ok(());
}