Compare commits

...
10 changed files with 231 additions and 70 deletions

No files matched your search

+12 -29
View File
@@ -4,14 +4,12 @@ on:
push:
tags:
- 'v*'
branches:
- 'feat/release-pipeline**'
workflow_dispatch:
inputs:
version_override:
description: 'Version override (leave empty to auto-detect from latest tag)'
description: 'Version (required, e.g. 8.1.0-rc.3)'
type: string
default: ''
required: true
env:
PRODUCTION_RELEASE_TAGS: '5.0,7,8'
@@ -29,33 +27,10 @@ jobs:
is_prerelease: ${{ steps.info.outputs.is_prerelease }}
docker_repos: ${{ steps.info.outputs.docker_repos }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
if: ${{ github.ref_type == 'branch' || (github.event_name == 'workflow_dispatch' && inputs.version_override == '') }}
with:
fetch-depth: 0
fetch-tags: true
- id: info
run: |
next_dev() {
# If latest tag is already a pre-release (e.g. v8.0.2-dev.1), reuse its base
# version (8.0.2-dev.1) so repeated branch runs don't bump the patch counter.
# If latest tag is a production release (e.g. v8.0.1), increment patch (8.0.2-dev.1).
local tag=$(git tag --sort=-version:refname | grep -m1 '^v' || echo "v0.0.0")
local ver="${tag#v}"
if [[ "$ver" == *"-"* ]]; then
echo "${ver%%-*}-dev.1"
else
IFS='.' read -r M m p <<< "$ver"
echo "${M}.${m}.$((p + 1))-dev.1"
fi
}
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ inputs.version_override }}"
[[ -z "$VERSION" ]] && VERSION=$(next_dev)
elif [[ "${{ github.ref_type }}" == "branch" ]]; then
VERSION=$(next_dev)
else
VERSION="${GITHUB_REF#refs/tags/v}"
fi
@@ -333,7 +308,15 @@ jobs:
with:
go-version-file: go.mod
- run: |
make changelog CHANGELOG_VERSION=$(echo "${{ needs.determine-release-type.outputs.version }}" | cut -d'-' -f1)
VERSION="${{ needs.determine-release-type.outputs.version }}"
# For prereleases (e.g. 8.1.0-rc.2), pass the full version so calens finds
# changelog/8.1.0-rc.2_*/ rather than falling through to the missing 8.1.0_*/ dir.
if [[ "$VERSION" == *-* ]]; then
CHANGELOG_VERSION="$VERSION"
else
CHANGELOG_VERSION=$(echo "$VERSION" | cut -d'-' -f1)
fi
make changelog CHANGELOG_VERSION="$CHANGELOG_VERSION"
# calens produces empty output when no versioned changelog directory exists (e.g. dev builds).
# Fall back to a pointer to the unreleased entries.
if [[ $(wc -l < ocis/dist/CHANGELOG.md) -lt 5 ]]; then
@@ -405,7 +388,7 @@ jobs:
python3 scripts/audit-release.py \
--version "${{ needs.determine-release-type.outputs.version }}" \
--dir release-assets/ \
--github-release --docker
--github-release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+1 -1
View File
@@ -97,7 +97,7 @@ require (
go.opentelemetry.io/otel/trace v1.44.0
golang.org/x/crypto v0.53.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.56.0
golang.org/x/oauth2 v0.36.0
golang.org/x/sync v0.21.0
+2 -2
View File
@@ -1027,8 +1027,8 @@ golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f h1:W3F4c+6OLc6H2lb//N1q4WpJk
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f/go.mod h1:J1xhfL/vlindoeF/aINzNzt2Bket5bjo9sdOYzOsU80=
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.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=
+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 {
+2 -1
View File
@@ -2277,7 +2277,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
@@ -2285,6 +2285,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