Исправьте кадрирование и очистку рабочих файлов кодека
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"messenger/internal/imaging"
|
||||
"messenger/internal/platform/apperr"
|
||||
"messenger/internal/platform/faultbarrier"
|
||||
"messenger/internal/platform/ident"
|
||||
@@ -35,10 +36,10 @@ type Config struct {
|
||||
// Binary operations report unavailability in that mode.
|
||||
func NewService(attachments AttachmentRepository, chats ChatMembership, blobs Blobs, cfg Config) *Service {
|
||||
if cfg.MaxBytes == 0 {
|
||||
cfg.MaxBytes = MaxUploadBytes
|
||||
cfg.MaxBytes = imaging.MaxUploadBytes
|
||||
}
|
||||
if cfg.MaxPixels == 0 {
|
||||
cfg.MaxPixels = MaxImagePixels
|
||||
cfg.MaxPixels = imaging.MaxImagePixels
|
||||
}
|
||||
return &Service{
|
||||
attachments: attachments,
|
||||
|
||||
@@ -10,12 +10,10 @@ import (
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"messenger/internal/imaging"
|
||||
"messenger/internal/platform/apperr"
|
||||
)
|
||||
|
||||
const MaxUploadBytes int64 = 10 * 1024 * 1024
|
||||
const MaxImagePixels int64 = 40_000_000
|
||||
|
||||
var imageFormats = map[string]string{
|
||||
"image/png": "png",
|
||||
"image/jpeg": "jpeg",
|
||||
@@ -36,7 +34,7 @@ func ValidateFilename(name string) error {
|
||||
// The small header is replayed into the decoder; pixels are allocated only
|
||||
// after checking dimensions. The caller serializes decoding per replica.
|
||||
func ValidateImage(r io.Reader, mime string, maxPixels int64) error {
|
||||
limited := io.LimitReader(r, MaxUploadBytes+1)
|
||||
limited := io.LimitReader(r, imaging.MaxUploadBytes+1)
|
||||
var header bytes.Buffer
|
||||
cfg, format, err := image.DecodeConfig(io.TeeReader(limited, &header))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user