fix: fixed the empty mount ID for storage-users (#12492)

* fix: fixed the empty mount ID for storage-users

* bump deps
This commit is contained in:
Roman Perekhod authored and GitHub committed 2026-07-02 14:25:24 +02:00
1 parent 7998d2c5a6
commit 10bed5f347
17 files changed
+310 -52

No files matched your search

@@ -0,0 +1,5 @@
Bugfix: Fix the empty mount ID for reva config.
We fixed the empty mount ID for storage-users
https://github.com/owncloud/ocis/pull/12492
+1
View File
@@ -3,3 +3,4 @@ Enhancement: Bump Reva version
bumped reva version
https://github.com/owncloud/ocis/pull/12410
https://github.com/owncloud/ocis/pull/12492
+2 -2
View File
@@ -64,7 +64,7 @@ require (
github.com/open-policy-agent/opa v1.12.3
github.com/orcaman/concurrent-map v1.0.0
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
github.com/owncloud/reva/v2 v2.0.0-20260617102227-727f0725aa36
github.com/owncloud/reva/v2 v2.0.0-20260702095801-b6833225e5d0
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.12
github.com/prometheus/client_golang v1.23.2
@@ -96,7 +96,7 @@ require (
go.opentelemetry.io/otel/trace v1.44.0
golang.org/x/crypto v0.52.0
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f
golang.org/x/image v0.42.0
golang.org/x/image v0.43.0
golang.org/x/net v0.55.0
golang.org/x/oauth2 v0.36.0
golang.org/x/sync v0.21.0
+4 -4
View File
@@ -739,8 +739,8 @@ github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HD
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 h1:JRidLTAKhnvyLMRtVtSF4lhBa0NSAOs6fof+d6JnKII=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245/go.mod h1:z61VMGAJRtR1nbgXWiNoCkxUXP1B3Je9rMuJbnGd+Og=
github.com/owncloud/reva/v2 v2.0.0-20260617102227-727f0725aa36 h1:ufRvlr1wHF96u9o7+1QRjQ0XumYAq4HETNfXgs4IgJo=
github.com/owncloud/reva/v2 v2.0.0-20260617102227-727f0725aa36/go.mod h1:oHjvB9PhfF8QqiNGz7Hd4AVvR7CSPx3CLVRxUzmjK0w=
github.com/owncloud/reva/v2 v2.0.0-20260702095801-b6833225e5d0 h1:A8iP4Vq1JLQgrIpsa7JtJo7C+ehTbGUdg5/ilekLigA=
github.com/owncloud/reva/v2 v2.0.0-20260702095801-b6833225e5d0/go.mod h1:oHjvB9PhfF8QqiNGz7Hd4AVvR7CSPx3CLVRxUzmjK0w=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pablodz/inotifywaitgo v0.0.9 h1:njquRbBU7fuwIe5rEvtaniVBjwWzcpdUVptSgzFqZsw=
@@ -1037,8 +1037,8 @@ golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f/go.mod h1:J1xhfL/vlindoeF/aI
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
golang.org/x/image v0.42.0 h1:1gSs6ehNWXLbkHBIPcWztk3D/6aIA/8hauiAYtlodVY=
golang.org/x/image v0.42.0/go.mod h1:rrpelvGFt+kLPAjPM4HeWPgrl0FtafueU//e5N0qk/Q=
golang.org/x/image v0.43.0 h1:FLxcP4ec2350nTfOC8ysKtqYSIFbk/QGjw1ZHNP4tsY=
golang.org/x/image v0.43.0/go.mod h1:rrpelvGFt+kLPAjPM4HeWPgrl0FtafueU//e5N0qk/Q=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@@ -214,6 +214,7 @@ func Ocis(cfg *config.Config) map[string]interface{} {
// OcisNoEvents is the config mapping for the ocis storage driver emitting no events
func OcisNoEvents(cfg *config.Config) map[string]interface{} {
return map[string]interface{}{
"mount_id": cfg.MountID,
"metadata_backend": "messagepack",
"propagator": cfg.Drivers.OCIS.Propagator,
"async_propagator_options": map[string]interface{}{
@@ -272,6 +273,7 @@ func S3(cfg *config.Config) map[string]interface{} {
// S3NG is the config mapping for the s3ng storage driver
func S3NG(cfg *config.Config) map[string]interface{} {
return map[string]interface{}{
"mount_id": cfg.MountID,
"metadata_backend": "messagepack",
"propagator": cfg.Drivers.S3NG.Propagator,
"async_propagator_options": map[string]interface{}{
@@ -338,6 +340,7 @@ func S3NG(cfg *config.Config) map[string]interface{} {
// S3NGNoEvents is the config mapping for the s3ng storage driver emitting no events
func S3NGNoEvents(cfg *config.Config) map[string]interface{} {
return map[string]interface{}{
"mount_id": cfg.MountID,
"metadata_backend": "messagepack",
"propagator": cfg.Drivers.S3NG.Propagator,
"async_propagator_options": map[string]interface{}{
@@ -39,6 +39,7 @@ type config struct {
ExposeRecipientDisplayName bool `mapstructure:"expose_recipient_display_name"`
ServiceAccountID string `mapstructure:"service_account_id"`
ServiceAccountSecret string `mapstructure:"service_account_secret"`
AllowHTTP bool `mapstructure:"allow_http"`
}
func (c *config) ApplyDefaults() {
@@ -22,6 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net/url"
"reflect"
"strings"
@@ -196,3 +197,28 @@ func getProtocolName(p Protocol) string {
s := strings.Split(n, ".")
return strings.ToLower(s[len(s)-1])
}
// validateURIScheme rejects a URI whose scheme is not https. Plain http is
// only accepted when allowHTTP is true. The URI must have a non-empty host.
// Webapp URI templates are accepted because RFC 6570 placeholders only ever
// appear in the path/query, never in the scheme or authority.
func validateURIScheme(raw string, allowHTTP bool) error {
u, err := url.Parse(raw)
if err != nil {
return fmt.Errorf("invalid uri %q: %w", raw, err)
}
if u.Host == "" {
return fmt.Errorf("invalid uri %q: missing host", raw)
}
switch u.Scheme {
case "https":
return nil
case "http":
if allowHTTP {
return nil
}
return fmt.Errorf("invalid uri %q: plain http is not allowed", raw)
default:
return fmt.Errorf("invalid uri %q: scheme %q is not allowed", raw, u.Scheme)
}
}
+18 -2
View File
@@ -47,6 +47,7 @@ var validate = validator.New()
type sharesHandler struct {
gatewaySelector *pool.Selector[gateway.GatewayAPIClient]
exposeRecipientDisplayName bool
allowHTTP bool
}
func (h *sharesHandler) init(c *config) error {
@@ -59,6 +60,7 @@ func (h *sharesHandler) init(c *config) error {
h.gatewaySelector = gatewaySelector
h.exposeRecipientDisplayName = c.ExposeRecipientDisplayName
h.allowHTTP = c.AllowHTTP
return nil
}
@@ -82,7 +84,7 @@ type createShareRequest struct {
func (h *sharesHandler) CreateShare(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
log := appctx.GetLogger(ctx)
req, err := getCreateShareRequest(r)
req, err := h.getCreateShareRequest(r)
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorInvalidParameter, err.Error(), nil)
return
@@ -245,7 +247,7 @@ func getIDAndMeshProvider(user string) (id, provider string, err error) {
return id, provider, nil
}
func getCreateShareRequest(r *http.Request) (*createShareRequest, error) {
func (h *sharesHandler) getCreateShareRequest(r *http.Request) (*createShareRequest, error) {
var req createShareRequest
contentType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err == nil && contentType == "application/json" {
@@ -259,6 +261,20 @@ func getCreateShareRequest(r *http.Request) (*createShareRequest, error) {
if err := validate.Struct(req); err != nil {
return nil, err
}
// validate the URI scheme of every protocol that carries a remote URI, so
// that no downstream code consumes an unvalidated URI.
for _, p := range req.Protocols {
switch proto := p.(type) {
case *WebDAV:
if err := validateURIScheme(proto.URI, h.allowHTTP); err != nil {
return nil, err
}
case *Webapp:
if err := validateURIScheme(proto.URITemplate, h.allowHTTP); err != nil {
return nil, err
}
}
}
return &req, nil
}
+32 -4
View File
@@ -25,11 +25,13 @@ import (
"encoding/xml"
"io"
"io/fs"
"net"
"net/http"
"net/url"
"path/filepath"
"regexp"
"strings"
"time"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
@@ -100,6 +102,20 @@ func (BearerAuthenticator) Close() error {
return nil
}
// noRedirectRoundTripper wraps an http.RoundTripper and tags every outgoing
// request with gowebdav's XInhibitRedirect header. The default CheckRedirect
// installed by gowebdav.NewAuthClient then returns http.ErrUseLastResponse on
// any 3xx response, so the http.Client never follows the redirect.
type noRedirectRoundTripper struct {
base http.RoundTripper
}
func (t *noRedirectRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
clonedRequest := req.Clone(req.Context())
clonedRequest.Header.Set(gowebdav.XInhibitRedirect, "1")
return t.base.RoundTrip(clonedRequest)
}
// New creates an OCM storage driver.
func New(m map[string]interface{}, _ events.Stream, _ *zerolog.Logger) (storage.FS, error) {
var c config
@@ -204,11 +220,23 @@ func (d *driver) webdavClient(ctx context.Context, forUser *userpb.UserId, ref *
// FIXME: it's still not clear from the OCM APIs how to use the shared secret
// will use as a token in the bearer authentication as this is the reva implementation
c := gowebdav.NewAuthClient(endpoint, gowebdav.NewPreemptiveAuth(BearerAuthenticator{Token: secret}))
if d.c.Insecure {
c.SetTransport(&http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
})
base := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
MaxIdleConnsPerHost: 32, // Bamped up from 2 to keep connections hot
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
if d.c.Insecure {
base.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
c.SetTransport(&noRedirectRoundTripper{base: base})
return c, share, rel, nil
}
@@ -438,7 +438,7 @@ func (fs *Decomposedfs) Postprocessing(ch <-chan events.Event) {
URL: s,
SpaceOwner: n.SpaceOwnerOrManager(ctx),
ExecutingUser: &user.User{Id: &user.UserId{OpaqueId: "postprocessing-restart"}}, // send nil instead?
ResourceID: &provider.ResourceId{SpaceId: n.SpaceID, OpaqueId: n.ID},
ResourceID: &provider.ResourceId{StorageId: session.ProviderID(), SpaceId: n.SpaceID, OpaqueId: n.ID},
Filename: session.Filename(),
Filesize: uint64(session.Size()),
}); err != nil {
+12
View File
@@ -12,6 +12,8 @@ import (
"image"
"image/color"
"io"
"golang.org/x/image/internal/safemath"
)
// ErrUnsupported means that the input BMP image uses a valid but unsupported
@@ -190,6 +192,16 @@ func decodeConfig(r io.Reader) (config image.Config, bitsPerPixel int, topDown b
if width < 0 || height < 0 {
return image.Config{}, 0, false, false, ErrUnsupported
}
if (width == 0) != (height == 0) {
// We'll take 0x0, but Nx0 or 0xN is suspicious.
return image.Config{}, 0, false, false, ErrUnsupported
}
// Check that the image fits in memory.
// This conservatively assumes 4 bytes per pixel,
// rather than using the actual pixel size.
if _, ok := safemath.Mul3(width, height, 4); !ok {
return image.Config{}, 0, false, false, ErrUnsupported
}
// We only support 1 plane and 8, 24 or 32 bits per pixel and no
// compression.
planes, bpp, compression := readUint16(b[26:28]), readUint16(b[28:30]), readUint32(b[30:34])
+6
View File
@@ -348,6 +348,9 @@ func makeCachedPairPosGlyph(cov indexLookupFunc, num int, buf []byte) kernFunc {
count := int(u16(glyphs[offset:]))
for i := 0; i < count; i++ {
if offset+2+i*4+4 > len(glyphs) {
return 0, errInvalidGPOSTable
}
secondGlyphIndex := GlyphIndex(int(u16(glyphs[offset+2+i*4:])))
if secondGlyphIndex == b {
return int16(u16(glyphs[offset+2+i*4+2:])), nil
@@ -372,6 +375,9 @@ func makeCachedPairPosClass(cov indexLookupFunc, num1, num2 int, cdef1, cdef2 cl
}
idxa := cdef1(a)
idxb := cdef2(b)
if idxa < 0 || idxa >= num1 || idxb < 0 || idxb >= num2 {
return 0, errInvalidGPOSTable
}
return int16(u16(glyphs[(idxb+idxa*num2)*2:])), nil
}
}
+31
View File
@@ -0,0 +1,31 @@
// Copyright 2026 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package safemath contains overflow-safe math functions.
package safemath
import "math/bits"
// Mul3 returns (x * y * z), unless at least one argument is negative or if the
// computation overflows the int type.
func Mul3(x, y, z int) (_ int, ok bool) {
// The following is copied from image/geom.go in std,
// but returns an explicit ok/not-ok rather than using -1 to indicate an error.
if x < 0 || y < 0 || z < 0 {
return -1, false
}
hi, lo := bits.Mul64(uint64(x), uint64(y))
if hi != 0 {
return -1, false
}
hi, lo = bits.Mul64(lo, uint64(z))
if hi != 0 {
return -1, false
}
a := int(lo)
if a < 0 || uint64(a) != lo {
return -1, false
}
return a, true
}
+20 -6
View File
@@ -5,7 +5,9 @@
package tiff
import (
"fmt"
"io"
"math"
"slices"
)
@@ -35,22 +37,34 @@ func (b *buffer) fill(end int) error {
}
func (b *buffer) ReadAt(p []byte, off int64) (int, error) {
o := int(off)
end := o + len(p)
if int64(end) != off+int64(len(p)) {
if off < 0 {
// Impossible in correct usage, but check for safety.
return 0, fmt.Errorf("invalid ReadAt offset %v (bug)", off)
}
end64 := off + int64(len(p))
if end64 < off || end64 > math.MaxInt {
return 0, io.ErrUnexpectedEOF
}
end := int(end64)
err := b.fill(end)
end = min(end, len(b.buf))
return copy(p, b.buf[min(o, end):end]), err
return copy(p, b.buf[min(int(off), end):end]), err
}
// Slice returns a slice of the underlying buffer. The slice contains
// n bytes starting at offset off.
func (b *buffer) Slice(off, n int) ([]byte, error) {
func (b *buffer) Slice(off, n int64) ([]byte, error) {
if off < 0 || n < 0 {
// Impossible in correct usage, but check for safety.
return nil, fmt.Errorf("invalid negative input to Slice(%v, %v) (bug)", off, n)
}
end := off + n
if err := b.fill(end); err != nil {
if end < 0 || end > math.MaxInt {
// end is too large. Treat this as a read error.
return nil, io.ErrUnexpectedEOF
}
if err := b.fill(int(end)); err != nil {
return nil, err
}
return b.buf[off:end], nil
+132 -30
View File
@@ -11,7 +11,6 @@ import (
"bytes"
"compress/zlib"
"encoding/binary"
"errors"
"fmt"
"image"
"image/color"
@@ -19,6 +18,7 @@ import (
"math"
"golang.org/x/image/ccitt"
"golang.org/x/image/internal/safemath"
"golang.org/x/image/tiff/lzw"
)
@@ -95,6 +95,7 @@ type decoder struct {
mode imageMode
bpp uint
features map[int][]uint
ifd map[int][ifdLen]byte
palette []color.Color
buf []byte
@@ -113,9 +114,23 @@ func (d *decoder) firstVal(tag int) uint {
return f[0]
}
// firstIntVal returns the first int of the features entry with the given tag,
// or 0 if the tag does not exist.
// If the tag overflows an int, it returns an error.
func (d *decoder) firstIntVal(tag int) (int, error) {
v := d.firstVal(tag)
if v > math.MaxInt {
return 0, FormatError("IFD value too large")
}
return int(v), nil
}
// ifdUint decodes the IFD entry in p, which must be of the Byte, Short
// or Long type, and returns the decoded uint values.
func (d *decoder) ifdUint(p []byte) (u []uint, err error) {
//
// maxCount limits the number of values.
// If the entry contains more than maxCount values, only the first maxCount are parsed.
func (d *decoder) ifdUint(p []byte, maxCount int) (u []uint, err error) {
var raw []byte
if len(p) < ifdLen {
return nil, FormatError("bad IFD entry")
@@ -130,9 +145,11 @@ func (d *decoder) ifdUint(p []byte) (u []uint, err error) {
if count > math.MaxInt32/lengths[datatype] {
return nil, FormatError("IFD data too large")
}
truncatedCount := min(int(count), maxCount)
if datalen := lengths[datatype] * count; datalen > 4 {
truncatedLen := uint64(lengths[datatype]) * uint64(truncatedCount)
// The IFD contains a pointer to the real value.
raw, err = safeReadAt(d.r, uint64(datalen), int64(d.byteOrder.Uint32(p[8:12])))
raw, err = safeReadAt(d.r, truncatedLen, int64(d.byteOrder.Uint32(p[8:12])))
} else {
raw = p[8 : 8+datalen]
}
@@ -140,18 +157,18 @@ func (d *decoder) ifdUint(p []byte) (u []uint, err error) {
return nil, err
}
u = make([]uint, count)
u = make([]uint, truncatedCount)
switch datatype {
case dtByte:
for i := uint32(0); i < count; i++ {
for i := range u {
u[i] = uint(raw[i])
}
case dtShort:
for i := uint32(0); i < count; i++ {
for i := range u {
u[i] = uint(d.byteOrder.Uint16(raw[2*i : 2*(i+1)]))
}
case dtLong:
for i := uint32(0); i < count; i++ {
for i := range u {
u[i] = uint(d.byteOrder.Uint32(raw[4*i : 4*(i+1)]))
}
default:
@@ -160,10 +177,30 @@ func (d *decoder) ifdUint(p []byte) (u []uint, err error) {
return u, nil
}
// parseIFDOffsets parses an IFD entry stored in d.ifd using ifdUint.
// For IFD entries which can be large, we delay reading and parsing the entry
// until we know the image size, which lets us set reasonable bounds on the IFD entry.
func (d *decoder) parseIFDOffsets(tag int, maxCount int) (u []uint, err error) {
p, ok := d.ifd[tag]
if !ok {
return nil, nil
}
return d.ifdUint(p[:], maxCount)
}
// parseIFD decides whether the IFD entry in p is "interesting" and
// stows away the data in the decoder. It returns the tag number of the
// entry and an error, if any.
func (d *decoder) parseIFD(p []byte) (int, error) {
// smallEntryMaxCount is the limit to use for parsed IFD entries that
// don't scale with the image size.
//
// We could be more precise and limit the number of entries to exactly the
// correct limit (for example, tTileWidth should always have exactly one value),
// but 16 is small enough to prevent excessive allocation and large enough to
// allow for any multi-value entry.
const smallEntryMaxCount = 16
tag := d.byteOrder.Uint16(p[0:2])
switch tag {
case tBitsPerSample,
@@ -171,30 +208,36 @@ func (d *decoder) parseIFD(p []byte) (int, error) {
tPhotometricInterpretation,
tCompression,
tPredictor,
tStripOffsets,
tStripByteCounts,
tRowsPerStrip,
tTileWidth,
tTileLength,
tTileOffsets,
tTileByteCounts,
tImageLength,
tImageWidth,
tFillOrder,
tT4Options,
tT6Options:
val, err := d.ifdUint(p)
val, err := d.ifdUint(p, smallEntryMaxCount)
if err != nil {
return 0, err
}
d.features[int(tag)] = val
case tStripOffsets,
tStripByteCounts,
tTileOffsets,
tTileByteCounts:
// These keys may contain many values.
// Stash the IFD entry for later parsing.
var v [ifdLen]byte
copy(v[:], p)
d.ifd[int(tag)] = v
case tColorMap:
val, err := d.ifdUint(p)
const maxColors = 256
val, err := d.ifdUint(p, (3*maxColors)+1)
if err != nil {
return 0, err
}
numcolors := len(val) / 3
if len(val)%3 != 0 || numcolors <= 0 || numcolors > 256 {
if len(val)%3 != 0 || numcolors <= 0 || numcolors > maxColors {
return 0, FormatError("bad ColorMap length")
}
d.palette = make([]color.Color, numcolors)
@@ -211,7 +254,7 @@ func (d *decoder) parseIFD(p []byte) (int, error) {
// the value is not 1 [= unsigned integer data], a Baseline
// TIFF reader that cannot handle the SampleFormat value
// must terminate the import process gracefully.
val, err := d.ifdUint(p)
val, err := d.ifdUint(p, smallEntryMaxCount)
if err != nil {
return 0, err
}
@@ -450,10 +493,15 @@ func (d *decoder) decode(dst image.Image, xmin, ymin, xmax, ymax int) error {
return nil
}
// maxBytesPerPixel is the maximum possible bytes-per-pixel,
// used for conservative bounds checking.
const maxBytesPerPixel = 8
func newDecoder(r io.Reader) (*decoder, error) {
d := &decoder{
r: newReaderAt(r),
features: make(map[int][]uint),
ifd: make(map[int][ifdLen]byte),
}
p := make([]byte, 8)
@@ -499,10 +547,20 @@ func newDecoder(r io.Reader) (*decoder, error) {
prevTag = tag
}
d.config.Width = int(d.firstVal(tImageWidth))
d.config.Height = int(d.firstVal(tImageLength))
if d.config.Width, err = d.firstIntVal(tImageWidth); err != nil {
return nil, err
}
if d.config.Height, err = d.firstIntVal(tImageLength); err != nil {
return nil, err
}
if d.config.Width == 0 || d.config.Height == 0 {
return nil, errors.New("tiff: zero-size image")
return nil, FormatError("zero-size image")
}
// Check that the image fits in memory.
// This conservatively assumes 8 bytes per pixel,
// rather than using the actual pixel size.
if _, ok := safemath.Mul3(d.config.Width, d.config.Height, maxBytesPerPixel); !ok {
return nil, FormatError("image too large")
}
if _, ok := d.features[tBitsPerSample]; !ok {
@@ -640,11 +698,15 @@ func Decode(r io.Reader) (img image.Image, err error) {
var blockOffsets, blockCounts []uint
if int(d.firstVal(tTileWidth)) != 0 {
if d.firstVal(tTileWidth) != 0 {
blockPadding = true
blockWidth = int(d.firstVal(tTileWidth))
blockHeight = int(d.firstVal(tTileLength))
if blockWidth, err = d.firstIntVal(tTileWidth); err != nil {
return nil, err
}
if blockHeight, err = d.firstIntVal(tTileLength); err != nil {
return nil, err
}
// The specification says that tile widths and lengths must be a multiple of 16.
// We currently permit invalid sizes, but reject anything too small to limit the
@@ -652,7 +714,30 @@ func Decode(r io.Reader) (img image.Image, err error) {
if blockWidth < 8 || blockHeight < 8 {
return nil, FormatError("tile size is too small")
}
// Same conservative assumption on bytes-per-pixel as for the image dimensions.
if _, ok := safemath.Mul3(blockWidth, blockHeight, maxBytesPerPixel); !ok {
return nil, FormatError("tile size is too large")
}
if blockWidth-d.config.Width > 16 || blockHeight-d.config.Height > 16 {
// Tiles may be padded to the nearest multiple of 16, but one of
// the dimensions of the tile exceeds the image dimension by more
// than padding would require.
//
// Typical TIFF tiles are 256x256, but 1024x1024 appears to be
// in occasional use. If the tile is both larger than the image
// and has more than 1024 pixels in one dimension, it's
// probably malicious input.
//
// Note that this still permits very large tiles,
// so long as the tile is smaller than the image dimensions.
// A gigapixel image with a 2048x2048 tile size
// (used in some GIS applications)
// will be valid because the image dimensions are much larger
// than the tile size.
if blockWidth > 1024 || blockHeight > 1024 {
return nil, FormatError("tile size exceeds image size")
}
}
if blockWidth != 0 {
blocksAcross = (d.config.Width + blockWidth - 1) / blockWidth
}
@@ -660,20 +745,34 @@ func Decode(r io.Reader) (img image.Image, err error) {
blocksDown = (d.config.Height + blockHeight - 1) / blockHeight
}
blockCounts = d.features[tTileByteCounts]
blockOffsets = d.features[tTileOffsets]
blockOffsets, err = d.parseIFDOffsets(tTileOffsets, blocksAcross*blocksDown)
if err != nil {
return nil, err
}
blockCounts, err = d.parseIFDOffsets(tTileByteCounts, blocksAcross*blocksDown)
if err != nil {
return nil, err
}
} else {
if int(d.firstVal(tRowsPerStrip)) != 0 {
blockHeight = int(d.firstVal(tRowsPerStrip))
if v := d.firstVal(tRowsPerStrip); v > 0 && v < uint(blockHeight) {
blockHeight = int(v)
}
if blockHeight != 0 {
// This can't overflow: We require that w*h*8 not overflow and
// blockHeight is no more than d.config.Height.
blocksDown = (d.config.Height + blockHeight - 1) / blockHeight
}
blockOffsets = d.features[tStripOffsets]
blockCounts = d.features[tStripByteCounts]
blockOffsets, err = d.parseIFDOffsets(tStripOffsets, blocksDown)
if err != nil {
return nil, err
}
blockCounts, err = d.parseIFDOffsets(tStripByteCounts, blocksDown)
if err != nil {
return nil, err
}
}
// Check if we have the right number of strips/tiles, offsets and counts.
@@ -728,8 +827,11 @@ func Decode(r io.Reader) (img image.Image, err error) {
// but some tools interpret a missing Compression value as none, so we do
// the same.
case cNone, 0:
if n > blockMaxDataSize {
return nil, FormatError("block data size too large")
}
if b, ok := d.r.(*buffer); ok {
d.buf, err = b.Slice(int(offset), int(n))
d.buf, err = b.Slice(offset, n)
} else {
d.buf, err = safeReadAt(d.r, uint64(n), offset)
}
+13 -1
View File
@@ -82,6 +82,9 @@ func decode(r io.Reader, configOnly bool) (image.Image, image.Config, error) {
if err != nil {
return nil, image.Config{}, err
}
if seenVP8X && (fh.Width != int(widthMinusOne)+1 || fh.Height != int(heightMinusOne)+1) {
return nil, image.Config{}, errInvalidFormat
}
if configOnly {
return nil, image.Config{
ColorModel: color.YCbCrModel,
@@ -111,7 +114,16 @@ func decode(r io.Reader, configOnly bool) (image.Image, image.Config, error) {
return nil, c, err
}
m, err := vp8l.Decode(chunkData)
return m, image.Config{}, err
if err != nil {
return nil, image.Config{}, err
}
if seenVP8X {
bounds := m.Bounds()
if bounds.Dx() != int(widthMinusOne)+1 || bounds.Dy() != int(heightMinusOne)+1 {
return nil, image.Config{}, errInvalidFormat
}
}
return m, image.Config{}, nil
case fccVP8X:
if seenVP8X {
+3 -2
View File
@@ -1322,7 +1322,7 @@ github.com/orcaman/concurrent-map
# github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
## explicit; go 1.18
github.com/owncloud/libre-graph-api-go
# github.com/owncloud/reva/v2 v2.0.0-20260617102227-727f0725aa36
# github.com/owncloud/reva/v2 v2.0.0-20260702095801-b6833225e5d0
## explicit; go 1.25.7
github.com/owncloud/reva/v2/cmd/revad/internal/grace
github.com/owncloud/reva/v2/cmd/revad/runtime
@@ -2282,7 +2282,7 @@ golang.org/x/exp/slices
golang.org/x/exp/slog
golang.org/x/exp/slog/internal
golang.org/x/exp/slog/internal/buffer
# golang.org/x/image v0.42.0
# golang.org/x/image v0.43.0
## explicit; go 1.25.0
golang.org/x/image/bmp
golang.org/x/image/ccitt
@@ -2290,6 +2290,7 @@ golang.org/x/image/font
golang.org/x/image/font/gofont/goregular
golang.org/x/image/font/opentype
golang.org/x/image/font/sfnt
golang.org/x/image/internal/safemath
golang.org/x/image/math/fixed
golang.org/x/image/riff
golang.org/x/image/tiff