allow accessing zip-archives with absolute paths

This commit is contained in:
B. Petersen
2021-12-29 18:00:34 +01:00
committed by bjoern
parent b656a60234
commit 9bc0824be6

View File

@@ -239,6 +239,14 @@ impl Message {
let archive = dc_open_file_std(context, archive)?;
let mut archive = zip::ZipArchive::new(archive)?;
// ignore first slash.
// this way, files can be accessed absolutely (`/index.html`) as well as relatively (`index.html`)
let name = if name.starts_with('/') {
name.split_at(1).1
} else {
name
};
let mut file = archive.by_name(name)?;
let mut buf = Vec::new();
@@ -695,6 +703,22 @@ mod tests {
Ok(())
}
#[async_std::test]
async fn test_get_blob_from_archive_with_absolute_paths() -> Result<()> {
let t = TestContext::new_alice().await;
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo").await?;
let instance = send_w30_instance(&t, chat_id).await?;
let buf = instance.get_blob_from_archive(&t, "/index.html").await?;
assert!(String::from_utf8_lossy(&buf).contains("document.write"));
assert!(instance
.get_blob_from_archive(&t, "/not-there")
.await
.is_err());
Ok(())
}
#[async_std::test]
async fn test_get_blob_from_archive_subdirs() -> Result<()> {
let t = TestContext::new_alice().await;