forked from mtusi2026/mtusi2026lab4
исправления
This commit is contained in:
@@ -28,7 +28,6 @@ import (
|
||||
const (
|
||||
maxAttachmentBytes = 10 << 20
|
||||
maxPixels = 40_000_000
|
||||
fullDecodePixels = 4_000_000 // полное декодирование только для небольших изображений
|
||||
)
|
||||
|
||||
func validFilename(s string) bool {
|
||||
@@ -139,11 +138,9 @@ func (a *api) handleUploadAttachment(w http.ResponseWriter, r *http.Request, u m
|
||||
writeError(w, http.StatusRequestEntityTooLarge, requestID, codeTooLarge, "image has too many pixels")
|
||||
return
|
||||
}
|
||||
if pixels <= fullDecodePixels {
|
||||
if _, _, err := image.Decode(io.NewSectionReader(tmp, 0, n)); err != nil {
|
||||
writeError(w, http.StatusUnsupportedMediaType, requestID, codeUnsupportedMedia, "corrupted image")
|
||||
return
|
||||
}
|
||||
if _, _, err := image.Decode(io.NewSectionReader(tmp, 0, n)); err != nil {
|
||||
writeError(w, http.StatusUnsupportedMediaType, requestID, codeUnsupportedMedia, "corrupted image")
|
||||
return
|
||||
}
|
||||
|
||||
id := idgen.GenerateUUIDv4()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"golang.org/x/sync/singleflight"
|
||||
@@ -50,9 +52,12 @@ func (a *api) authMiddleware(next func(w http.ResponseWriter, r *http.Request, u
|
||||
return
|
||||
}
|
||||
|
||||
u, ok, err := a.store.GetUserByID(r.Context(), userID)
|
||||
dbCtx, dbCancel := context.WithTimeout(r.Context(), 3*time.Second)
|
||||
defer dbCancel()
|
||||
|
||||
u, ok, err := a.store.GetUserByID(dbCtx, userID)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusServiceUnavailable, requestID, codeInternal, "database unavailable")
|
||||
writeError(w, http.StatusServiceUnavailable, requestID, codeUnavailable, "database unavailable")
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user