@@ -541,6 +541,46 @@ func TestUnpackFromLayers_DuplicateRawAnnotationAllowed(t *testing.T) {
541541 }
542542}
543543
544+ func TestUnpackFromLayers_PathSanitizationRejectsCollapsedPath (t * testing.T ) {
545+ // Build a ModelPack artifact whose annotation collapses entirely during
546+ // sanitization. This must fail before any file is written.
547+ artifact := testutil .NewModelPackArtifact (
548+ t ,
549+ modelpack.Model {
550+ Config : modelpack.ModelConfig {Format : string (types .FormatGGUF )},
551+ },
552+ testutil.LayerSpec {
553+ Path : filepath .Join (".." , ".." , "assets" , "dummy.gguf" ),
554+ RelativePath : "../../.." ,
555+ MediaType : oci .MediaType (modelpack .MediaTypeWeightGGUF ),
556+ },
557+ )
558+
559+ bundleRoot := t .TempDir ()
560+ _ , err := UnpackFromLayers (bundleRoot , artifact )
561+ if err == nil {
562+ t .Fatal ("Expected sanitization error, got nil" )
563+ }
564+ if ! strings .Contains (err .Error (), `invalid filepath annotation "../../.."` ) {
565+ t .Fatalf ("Expected error to mention original annotation, got: %v" , err )
566+ }
567+ if ! strings .Contains (err .Error (), `sanitized as ""` ) {
568+ t .Fatalf ("Expected error to mention sanitized path, got: %v" , err )
569+ }
570+ if ! strings .Contains (err .Error (), "empty path is not allowed" ) {
571+ t .Fatalf ("Expected error to mention sanitized validation failure, got: %v" , err )
572+ }
573+
574+ modelDir := filepath .Join (bundleRoot , ModelSubdir )
575+ entries , readErr := os .ReadDir (modelDir )
576+ if readErr != nil {
577+ t .Fatalf ("Expected model directory to exist, got: %v" , readErr )
578+ }
579+ if len (entries ) != 0 {
580+ t .Fatalf ("Expected no files to be written for rejected annotation, got %d entries" , len (entries ))
581+ }
582+ }
583+
544584func TestValidatePathWithinDirectory_RealFilesystem (t * testing.T ) {
545585 // Create a temporary directory structure
546586 baseDir := t .TempDir ()
0 commit comments