package artifacts import ( "os" "path/filepath" "strings" "gitea.maximumdirect.net/eric/narratio/internal/manifest" ) // MaxExtractionPayloadBytes bounds one validated Notarius lane or index payload. const MaxExtractionPayloadBytes int64 = 64 * 1024 * 1024 const ( extractStageName = "extract" extractionLaneKind = "notarius_lane" extractionMetadataRun = "narratio_run_id" ) // HydrateExtractionArtifacts marks extraction sources available only when the current // manifest contains one complete, internally consistent, succeeded extraction bundle. // Invalid, stale, incomplete, or unsafe records leave every extraction source unavailable. func (c *ArtifactCatalog) HydrateExtractionArtifacts( paths SessionPaths, m *manifest.Manifest, configured map[string]ExtractionArtifactDefinition, ) { if c == nil || m == nil || len(configured) == 0 { return } input, err := ResolveExtractionInputIdentity(paths, m) if err != nil { return } proof := InspectExtractionEvidence(paths, m, configured, input) if proof.State != ExtractionEvidenceValid { return } for sourceID, output := range proof.Outputs { _ = c.markAvailableFromExtractManifest( sourceID, output.Path, proof.ProducerRunID, output.Checksum, output.Size, output.Contract, ) } } func safeExtractionComponents(root, target string) bool { relative, err := filepath.Rel(filepath.Clean(root), filepath.Clean(target)) if err != nil || relative == "." || relative == ".." || strings.HasPrefix(relative, ".."+string(filepath.Separator)) { return false } current := filepath.Clean(root) for _, part := range strings.Split(relative, string(filepath.Separator)) { current = filepath.Join(current, part) info, err := os.Lstat(current) if err != nil || info.Mode()&os.ModeSymlink != 0 { return false } } return true } func pathWithinExtractionRoot(root, target string) bool { relative, err := filepath.Rel(filepath.Clean(root), filepath.Clean(target)) return err == nil && relative != "." && relative != ".." && !strings.HasPrefix(relative, ".."+string(filepath.Separator)) } func safeExtractionPathSegment(value string) bool { return value != "" && value != "." && value != ".." && filepath.Base(value) == value && !strings.ContainsAny(value, `/\\`) } func extractionMetadataString(metadata map[string]any, key string) string { value, _ := metadata[key].(string) return strings.TrimSpace(value) }