Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic when tmp path is inccurate #280

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion filesystem/iso9660/finalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ var (

// test creating an iso with el torito boot
func TestFinalizeElTorito(t *testing.T) {
finalizeElTorito(t, "")
dir, err := os.MkdirTemp("", "workspace")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
finalizeElTorito(t, dir)
}

func TestFinalizeElToritoWithInaccurateTmpDir(t *testing.T) {
finalizeElTorito(t, "")
dir, err := os.MkdirTemp("/tmp//", "workspace")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
finalizeElTorito(t, dir)
}

//nolint:thelper // this is not a helper function
func finalizeElTorito(t *testing.T, workspace string) {
blocksize := int64(2048)
f, err := os.CreateTemp("", "iso_finalize_test")
defer os.Remove(f.Name())
Expand All @@ -31,7 +50,7 @@ func TestFinalizeElTorito(t *testing.T) {
}

b := file.New(f, false)
fs, err := iso9660.Create(b, 0, 0, blocksize, "")
fs, err := iso9660.Create(b, 0, 0, blocksize, workspace)
if err != nil {
t.Fatalf("Failed to iso9660.Create: %v", err)
}
Expand Down
4 changes: 4 additions & 0 deletions filesystem/iso9660/iso9660.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path"
"path/filepath"

"github.com/diskfs/go-diskfs/backend"
"github.com/diskfs/go-diskfs/filesystem"
Expand Down Expand Up @@ -97,6 +98,9 @@ func Create(b backend.Storage, size, start, blocksize int64, workspace string) (
}
}

// sometimes, at least on macos, extra separators in path can cause panic
workdir = filepath.Clean(workdir)

// create root directory
// there is nothing in there
return &FileSystem{
Expand Down