Skip to content

Commit

Permalink
fix: segfault on long paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Feb 28, 2024
1 parent d0fa5ec commit b6ccc27
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api/src/npm/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,14 @@ pub fn create_npm_tarball<'a>(

for (path, content) in transpiled_files.iter() {
let mut header = Header::new_gnu();
header.set_path(format!("./package{path}")).unwrap();
header.set_path(format!("./package{path}")).map_err(|_e| {
// TODO(ry): Currently this PublishError is swallowed and turned into
// NpmTarballError. Change error type of this function to PublishError.
crate::tarball::PublishError::InvalidPath {
path: path.to_string(),
error: crate::ids::PackagePathValidationError::TooLong(path.len()),
}
})?;
header.set_size(content.len() as u64);
header.set_mode(0o777);
header.set_mtime(mtime);
Expand Down
10 changes: 10 additions & 0 deletions api/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,16 @@ pub mod tests {
assert_eq!(error.code, "missingConfigFile");
}

#[tokio::test]
async fn no_long_paths() {
let t = TestSetup::new().await;
let bytes = create_mock_tarball("no_long_paths");
let task = process_tarball_setup(&t, bytes).await;
assert_eq!(task.status, PublishingTaskStatus::Failure, "{task:#?}");
let error = task.error.unwrap();
assert_eq!(error.code, "npmTarballError");
}

#[tokio::test]
async fn global_type_augmentation1() {
let t = TestSetup::new().await;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This is a test module.
*
* @module
*/

/**
* This is a test constant.
*/
export const hello = "Hello, world!";
5 changes: 5 additions & 0 deletions api/testdata/tarballs/no_long_paths/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@scope/foo",
"version": "1.2.3",
"exports": "./a_very_long_filename_created_specifically_to_test_the_limitations_of_the_set_path_method_in_the_rust_tar_crate_exceeding_one_hundred_bytes.ts"
}

0 comments on commit b6ccc27

Please sign in to comment.