Files
vikunja/pkg/modules/imageutils/errors.go
T
kolaente f930d895c9 refactor(imageutils): move pixel-weighted decode semaphore
Attachment previews now decode through imageutils.Decode, which holds an
image's pixels against one process-wide budget until the caller is done
with the decoded image. Other decode sites move onto it next.
2026-10-20 23:05:30 +02:00

72 lines
2.1 KiB
Go

// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-present Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package imageutils
import (
"errors"
"fmt"
"net/http"
"code.vikunja.io/api/pkg/web"
)
// ErrImageTooLarge rejects hostile dimensions before decoding (GHSA-4vh2-39rq-rq8j).
type ErrImageTooLarge struct {
Width int
Height int
}
func (err *ErrImageTooLarge) Error() string {
return fmt.Sprintf("image dimensions %dx%d are invalid or exceed the maximum of %d pixels", err.Width, err.Height, MaxPixels)
}
const ErrCodeImageTooLarge = 4032
func (err *ErrImageTooLarge) HTTPError() web.HTTPError {
return web.HTTPError{
HTTPCode: http.StatusBadRequest,
Code: ErrCodeImageTooLarge,
Message: fmt.Sprintf("Image dimensions %dx%d are invalid or exceed the maximum of %d pixels.", err.Width, err.Height, MaxPixels),
}
}
func IsErrImageTooLarge(err error) bool {
var e *ErrImageTooLarge
return errors.As(err, &e)
}
type ErrDecodeBusy struct{}
func (err ErrDecodeBusy) Error() string {
return "Timed out waiting for capacity to decode an image"
}
const ErrCodeDecodeBusy = 4040
func (err ErrDecodeBusy) HTTPError() web.HTTPError {
return web.HTTPError{
HTTPCode: http.StatusServiceUnavailable,
Code: ErrCodeDecodeBusy,
Message: "The server is busy processing other images, please try again later.",
}
}
func IsErrDecodeBusy(err error) bool {
var busy ErrDecodeBusy
return errors.As(err, &busy)
}