fix: lint-archive error handling, test: big zip binary, v1.3.39

This commit is contained in:
“Naeel”
2026-05-03 21:24:44 +04:00
parent b7a8074c73
commit 21c11f84d0
4 changed files with 18 additions and 10 deletions
+12 -4
View File
@@ -5,6 +5,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
@@ -41,12 +42,19 @@ func (s *Server) handleLintArchive(w http.ResponseWriter, r *http.Request) {
return
}
// Ограничиваем тело запроса — не более maxArchiveBytes (+ небольшой overhead для multipart)
r.Body = http.MaxBytesReader(w, r.Body, maxArchiveBytes+4*1024)
// Hard-limit 10 MB чтобы соединение не обрывалось (MaxBytesReader с маленьким лимитом
// закрывает соединение до отправки ответа — клиент получает 000 вместо 413).
// Реальный лимит размера архива проверяется после чтения файла.
r.Body = http.MaxBytesReader(w, r.Body, 10*1024*1024)
if err := r.ParseMultipartForm(maxArchiveBytes); err != nil {
writeJSONError(w, http.StatusRequestEntityTooLarge,
fmt.Sprintf("архив слишком большой: максимум %d KB", maxArchiveBytes/1024))
var maxErr *http.MaxBytesError
if errors.As(err, &maxErr) {
writeJSONError(w, http.StatusRequestEntityTooLarge,
fmt.Sprintf("архив слишком большой: максимум %d KB", maxArchiveBytes/1024))
} else {
writeJSONError(w, http.StatusBadRequest, "ошибка разбора multipart: "+err.Error())
}
return
}