mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-11-26 19:40:04 +01:00
fix: reject truncated one-byte downloads
Qobuz/Akamai sometimes answers a stream request with HTTP 200 and a single-byte body (usually "f", the first byte of a FLAC header). The downloader treated that as success because it only compared against a known Content-Length; tagging then failed with a warning and the track was recorded as downloaded, leaving an unusable one-byte file. Reject payloads shorter than four bytes in the shared download paths and in the Qobuz mobile fallback so the normal retry and provider fallback logic runs instead. On repeated failure the track is marked failed rather than downloaded.
This commit is contained in:
2 files changed
+22
No files matched your search
@@ -45,6 +45,14 @@ type Downloader struct {
|
||||
// streams off CDNs that can sustain high per-connection throughput.
|
||||
const downloadBufferSize = 1 << 20
|
||||
|
||||
// minDownloadBytes rejects responses too short to be any real audio, video, or
|
||||
// image payload. Qobuz (via Akamai) intermittently answers a stream request
|
||||
// with HTTP 200 and a one-byte body, typically "f"; the downloader used to
|
||||
// accept that, tagging then failed with only a warning, and the track was
|
||||
// recorded as downloaded. Treating it as a download error lets the retry and
|
||||
// provider fallback paths run instead.
|
||||
const minDownloadBytes = 4
|
||||
|
||||
func New() *Downloader {
|
||||
return NewWithOptions(true, true, 0)
|
||||
}
|
||||
@@ -124,6 +132,9 @@ func (d *Downloader) streamEncrypted(
|
||||
if resp.ContentLength > 0 && written != resp.ContentLength {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if written < minDownloadBytes {
|
||||
return fmt.Errorf("download returned only %d byte(s); treating as a truncated response", written)
|
||||
}
|
||||
if err = out.Sync(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -252,6 +263,9 @@ func (d *Downloader) file(ctx context.Context, sourceURL, outputPath string, all
|
||||
if resp.ContentLength > 0 && written != resp.ContentLength {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if written < minDownloadBytes {
|
||||
return fmt.Errorf("download returned only %d byte(s); treating as a truncated response", written)
|
||||
}
|
||||
if err = out.Sync(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -598,6 +598,11 @@ func (c *Client) DownloadTrackFallback(ctx context.Context, trackID string, qual
|
||||
if err = out.Sync(); err != nil {
|
||||
return err
|
||||
}
|
||||
if info, statErr := out.Stat(); statErr != nil {
|
||||
return statErr
|
||||
} else if info.Size() < 4 {
|
||||
return fmt.Errorf("mobile fallback produced only %d byte(s); treating as a truncated response", info.Size())
|
||||
}
|
||||
success = true
|
||||
return nil
|
||||
}
|
||||
@@ -1209,6 +1214,9 @@ func (c *Client) mobileCopyURLToWriter(ctx context.Context, sourceURL string, ou
|
||||
if resp.ContentLength > 0 && written != resp.ContentLength {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if written < 4 {
|
||||
return fmt.Errorf("mobile fallback returned only %d byte(s); treating as a truncated response", written)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user