fix: review findings — clone-route audio sniffing, zip caps, filename sanitization, WAV response caps
- speakWithReference now validates the response IS audio via the same audioResultMIME sniff the sfx/enhance surfaces use — a 2xx JSON soft error or HTML proxy page was previously wrapped up as audio/wav bytes. - audioResultMIME moves to audio.go (next to speechMIME; it was defined in sfx.go but shared by enhance/clone) and learns the Ogg container normalization (application/ogg -> audio/ogg). - Stems zip unpack gains entry-count (16) and total-decompressed (1GB) caps on top of the existing per-entry cap — the per-entry bound alone still let a many-entry bomb multiply up. - sanitizeFilename drops NUL and both path separators too, so upload metadata can never smuggle directory structure to a file-writing shim. - New maxAudioResponseBytes (256MB) for bodies that ARE one audio clip (clone, enhance, sfx): a long WAV legitimately passes the 64MB JSON cap. - speakWithReference local renamed path -> upPath (naming parity with stems/enhance). Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WWCQcYStWXBYUy5sZWnbLT
This commit is contained in:
@@ -6,8 +6,10 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.stevedudenhoeffer.com/steve/majordomo/audio"
|
||||
@@ -169,6 +171,27 @@ func TestSeparateStemsRejectsEmptyZip(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeparateStemsRejectsTooManyEntries(t *testing.T) {
|
||||
entries := map[string]string{}
|
||||
for i := 0; i <= maxStemEntries; i++ {
|
||||
entries[fmt.Sprintf("stem%02d.wav", i)] = "X"
|
||||
}
|
||||
zipBody := stemsZipFixture(t, entries)
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/zip")
|
||||
_, _ = w.Write(zipBody)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
p := New(WithBaseURL(srv.URL), WithHTTPClient(srv.Client()))
|
||||
ss, _ := p.StemSeparatorModel("audioutils")
|
||||
_, err := ss.SeparateStems(context.Background(), audio.StemSeparationRequest{Audio: []byte("SONG")})
|
||||
var apiErr *llm.APIError
|
||||
if !errors.As(err, &apiErr) || !strings.Contains(apiErr.Message, "entries") {
|
||||
t.Fatalf("err = %v, want APIError for over-long stems zip", err)
|
||||
}
|
||||
}
|
||||
|
||||
// wavFixture is a minimal RIFF/WAVE header so http.DetectContentType sniffs
|
||||
// audio/wave.
|
||||
func wavFixture() []byte {
|
||||
|
||||
Reference in New Issue
Block a user