Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

fix(http): handle invalid gzip stream errors (#9767)

7y-95ea75dcc6758
diff --git a/weed/util/http/http_global_client_util.go b/weed/util/http/http_global_client_util.go
index 24e38f8c70..1a78bd412e 100644
--- a/weed/util/http/http_global_client_util.go
+++ b/weed/util/http/http_global_client_util.go
@@ -397,6 +397,9 @@ func ReadUrlAsStream(ctx context.Context, fileUrl, jwt string, cipherKey []byte,
switch contentEncoding {
case "gzip":
reader, err = gzip.NewReader(r.Body)
+ if err != nil {
+ return true, err
+ }
defer reader.Close()
default:
reader = r.Body
diff --git a/weed/util/http/http_global_client_util_test.go b/weed/util/http/http_global_client_util_test.go
index f24bd5aca8..cc17301e31 100644
--- a/weed/util/http/http_global_client_util_test.go
+++ b/weed/util/http/http_global_client_util_test.go
@@ -1,6 +1,11 @@
package http
-import "testing"
+import (
+ "context"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+)
func TestAppendQueryParameter(t *testing.T) {
testCases := []struct {
@@ -70,3 +75,19 @@ func TestAppendQueryParameter(t *testing.T) {
})
}
}
+
+func TestReadUrlAsStreamReturnsGzipReaderError(t *testing.T) {
+ InitGlobalHttpClient()
+
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Encoding", "gzip")
+ w.WriteHeader(http.StatusOK)
+ _, _ = w.Write([]byte("not gzip"))
+ }))
+ defer server.Close()
+
+ _, err := ReadUrlAsStream(context.Background(), server.URL, "", nil, false, true, 0, 0, func(data []byte) {})
+ if err == nil {
+ t.Fatal("ReadUrlAsStream returned nil error for invalid gzip response")
+ }
+}