Files
ocis/vendor/github.com/davidbyttow/govips/v2/vips/transcode.go
Michal Klos b9077d96d8 chore(deps): consolidate dependency and security bumps (#13081)
* chore(deps): consolidate dependency and security bumps

Dependabot PRs applied:
- #12878 qs 6.15.2 -> 6.16.0 (web/web-runtime)
- #13013 alpine 3.24.1 -> 3.24.2
- #13061 actions/checkout -> v7.0.1 (missed instance in k8s.yml)
- #13062 actions/setup-node -> v7.0.0 (missed instance in k8s.yml)
- #13075 simple-git 3.36.0 -> 4.0.1 (security)
- #13076 katex 0.16.45 -> 0.18.2+ (security)
- #13077 dompurify 3.4.13 -> 3.4.16 (security)
- #13079 go deps minor-and-patch group, 18 updates (opa 1.19.0 -> 1.21.1, otel 1.46 -> 1.47, bleve, govips, grpc-gateway, lico, tablewriter, logrus, gjson, x/exp, x/image, genproto, etc.)

Skipped (already satisfied on master): #12513, #12624, #12625, #12633

Manual security bumps via pnpm.overrides (no dependabot PR existed):
- axios -> 1.20.0
- smol-toml -> 1.9.0
- postcss -> 8.5.23
- postcss-selector-parser -> 7.1.6
- colord -> 2.9.4
- unhead -> 2.1.13
- markdown-it -> 14.3.1
- esbuild -> 0.28.1
- brace-expansion 5.0.11 -> 5.0.12

Not fixable: sprintf-js and elliptic have no patched version released upstream yet; left as-is.

go build and pnpm install verified clean.

* chore(deps): fix residual transitive vulns found by trivy

trivy flagged duplicate/stale resolutions that survived the earlier
override pass: dompurify (3.4.12 -> 3.4.16), qs (6.14.2 -> 6.16.0),
and fast-uri (3.1.7 -> 3.1.8, CVE-2026-86472). Added/bumped pnpm.overrides
accordingly. trivy fs scan of web/pnpm-lock.yaml now clean.

* chore(deps): bump reva to bac0e1ee144ab853a81c6b02142032f102dd245a

Pins github.com/owncloud/reva/v2 to bac0e1ee144ab853a81c6b02142032f102dd245a,
pulling in its go-playground/locales and huandu/xstrings version bumps.
Appends this PR to changelog/unreleased/bump-reva.md.

go build ./... verified clean after go mod vendor resync.

* fix(ci): revert unhead override, breaks web build

* revert: keep k8s.yml actions/checkout and setup-node pinned
2026-10-07 07:56:56 +02:00

105 lines
3.5 KiB
Go

package vips
import (
"errors"
"fmt"
"io"
)
// TranscodeOptions configures TranscodeStream.
type TranscodeOptions struct {
// Format is the output image type. ImageTypeUnknown keeps the
// input format (which must be one of the streaming-save formats:
// JPEG, PNG, WebP, HEIF, TIFF, GIF).
Format ImageType
// ImportParams configures the load. The Access field is ignored:
// TranscodeStream picks the access mode itself.
ImportParams *ImportParams
// ExportParams configures the encode; nil uses the format's
// defaults, exactly like SaveToWriter.
ExportParams *ExportParams
// AutoRotate applies the EXIF orientation to the pixels and clears
// the orientation tag. Orientations that need a non-sequential
// transform (3-8: 180° and 90°/270° families) force the image to be
// materialized first — see the package streaming documentation.
AutoRotate bool
}
// TranscodeStream decodes an image from r, optionally applies EXIF
// auto-rotation, and encodes it to w in the requested format. Encoded
// bytes are handed to w in chunks as they are produced and are
// byte-identical to the corresponding Export* method with the same
// parameters.
//
// The pipeline picks the cheapest decode strategy automatically:
//
// - Sequential fast path: when no random-access transform is needed
// (AutoRotate false, or EXIF orientation is 1 or 2), pixels flow
// from r to w in one pass. Peak memory is bounded by libvips line
// caches, independent of both file size and pixel count.
// - Materialized path: when AutoRotate requires a rotation, the
// decoded image is first rendered to memory or to an unlinked
// scratch file, depending on its decoded size and the configured
// threshold (SetStreamDiscThreshold, SetStreamScratchDir).
//
// Reader/decode errors (including truncated input) surface from this
// call: on the sequential path during the encode (the first full pass
// over the pixels), on the materialized path during materialization.
// In both cases the original reader/writer error is wrapped and
// matchable with errors.Is.
//
// govips knows nothing about the destination: w is the chunk callback.
// Compose on the consumer side with io.MultiWriter (hash while
// writing), io.Pipe (bridge to reader-shaped sinks), or io.Copy.
func TranscodeStream(r io.Reader, w io.Writer, opts *TranscodeOptions) error {
if r == nil {
return errors.New("transcode: reader is nil")
}
if w == nil {
return errors.New("transcode: writer is nil")
}
if opts == nil {
opts = &TranscodeOptions{}
}
importParams := NewImportParams()
if opts.ImportParams != nil {
*importParams = *opts.ImportParams
}
importParams.Access.Set(AccessSequential)
img, err := LoadImageFromReader(r, importParams)
if err != nil {
return fmt.Errorf("transcode: %w", err)
}
defer img.Close()
if opts.AutoRotate {
// Orientation is header metadata, available before any pixel is
// decoded. Orientations 1 (none) and 2 (horizontal flip) are
// sequential-safe; everything else transposes or reverses line
// order and needs random access.
if img.Orientation() >= 3 {
if err := img.materialize(); err != nil {
return fmt.Errorf("transcode: %w", err)
}
}
if err := img.AutoRotate(); err != nil {
return fmt.Errorf("transcode: autorotate: %w", err)
}
}
format := opts.Format
if format == ImageTypeUnknown {
format = img.Format()
}
if err := img.SaveToWriter(w, format, opts.ExportParams); err != nil {
return fmt.Errorf("transcode: %w", err)
}
return nil
}