Handle PNG EXIF and distinguish transient encoder crashes from invalid images
This commit is contained in:
@@ -100,3 +100,5 @@ python3 student-tests/retry_backpressure.py
|
||||
## Источники и ИИ
|
||||
|
||||
Собственная база ЛР4; контракты преподавателя текущей ЛР; первичные материалы: [Valkey Streams/XAUTOCLAIM](https://valkey.io/commands/xautoclaim/), [Valkey persistence](https://valkey.io/topics/persistence/), [imaging](https://pkg.go.dev/github.com/disintegration/imaging). Использовался ИИ Codex для реализации, тестов и подготовки объяснений. Результаты получены реальным запуском; автор должен уметь объяснить код и ограничения на защите.
|
||||
|
||||
Финальный encoder различает invalid image (child exit65) и временную аварию/kill/deadline: последняя проходит bounded retry, а не маркирует корректный файл invalid_image. EXIF обрабатывается для JPEG APP1 и PNG eXIf, перед resize. Финальные race/PG проверки актуальных исходников, включая PNG EXIF и аварии subprocess, — `evidence/race-final.txt`. Для проверки использован уже скачанный совместимый Go1.24.4/GCC/cwebp test toolchain с read-only bind текущих cmd/internal (в ЛР6 также текущие go.mod/go.sum); публичный `make test-race` сам собирает такой toolchain из Dockerfile, соседняя лабораторная для запуска/проверки не требуется.
|
||||
|
||||
@@ -27,6 +27,9 @@ func env(key, fallback string) string {
|
||||
}
|
||||
func main() {
|
||||
if err := run(); err != nil {
|
||||
if errors.Is(err, messenger.ErrInvalidImage) {
|
||||
os.Exit(65)
|
||||
}
|
||||
slog.Error("server failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@@ -149,6 +149,7 @@ services:
|
||||
s3-init: {condition: service_completed_successfully}
|
||||
restart: unless-stopped
|
||||
tests:
|
||||
volumes: [go_test_cache:/root/.cache/go-build]
|
||||
image: mtusi-messenger-tests:lab5
|
||||
cpus: 2
|
||||
mem_limit: 1024m
|
||||
@@ -157,6 +158,8 @@ services:
|
||||
context: .
|
||||
target: tests
|
||||
environment:
|
||||
GOMAXPROCS: "2"
|
||||
GOFLAGS: -p=2
|
||||
DATABASE_TEST_URL_FILE: /run/secrets/database_url
|
||||
secrets: [database_url]
|
||||
depends_on:
|
||||
@@ -187,6 +190,7 @@ secrets:
|
||||
cache_url: {file: ./secrets/cache_url}
|
||||
cursor_key: {file: ./secrets/cursor_key}
|
||||
volumes:
|
||||
go_test_cache:
|
||||
broker_data:
|
||||
s3_data:
|
||||
postgres_data:
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
? mtusi/messenger/cmd/server [no test files]
|
||||
? mtusi/messenger/internal/database [no test files]
|
||||
=== RUN TestDatabaseConcurrentHTTP
|
||||
database_test.go:162: 100 confirmed messages from 10 clients through real HTTP and PostgreSQL; race detector enabled
|
||||
--- PASS: TestDatabaseConcurrentHTTP (1.77s)
|
||||
=== RUN TestPasswordFullUnicodeRange
|
||||
--- PASS: TestPasswordFullUnicodeRange (2.31s)
|
||||
=== RUN TestTransformFailureClassification
|
||||
--- PASS: TestTransformFailureClassification (0.00s)
|
||||
=== RUN TestFitFloorNoUpscale
|
||||
--- PASS: TestFitFloorNoUpscale (0.00s)
|
||||
=== RUN TestTransformAlphaAndEXIF
|
||||
--- PASS: TestTransformAlphaAndEXIF (0.25s)
|
||||
PASS
|
||||
ok mtusi/messenger/internal/messenger 5.359s
|
||||
@@ -0,0 +1,19 @@
|
||||
Volume "mtusi-lab5-kraykin_go_test_cache" Creating
|
||||
Volume "mtusi-lab5-kraykin_go_test_cache" Created
|
||||
? mtusi/messenger/cmd/server [no test files]
|
||||
? mtusi/messenger/internal/database [no test files]
|
||||
=== RUN TestDatabaseConcurrentHTTP
|
||||
database_test.go:162: 100 confirmed messages from 10 clients through real HTTP and PostgreSQL; race detector enabled
|
||||
--- PASS: TestDatabaseConcurrentHTTP (1.78s)
|
||||
=== RUN TestPasswordFullUnicodeRange
|
||||
--- PASS: TestPasswordFullUnicodeRange (2.17s)
|
||||
=== RUN TestTransformFailureClassification
|
||||
--- PASS: TestTransformFailureClassification (0.00s)
|
||||
=== RUN TestFitFloorNoUpscale
|
||||
--- PASS: TestFitFloorNoUpscale (0.00s)
|
||||
=== RUN TestTransformAlphaAndEXIF
|
||||
--- PASS: TestTransformAlphaAndEXIF (0.21s)
|
||||
=== RUN TestPNGEXIFAndMalformedIFD
|
||||
--- PASS: TestPNGEXIFAndMalformedIFD (0.11s)
|
||||
PASS
|
||||
ok mtusi/messenger/internal/messenger 5.283s
|
||||
+164
-5
@@ -1,19 +1,178 @@
|
||||
docker compose --profile verify run --build --rm tests
|
||||
Compose can now delegate builds to bake for better performance.
|
||||
To do so, set COMPOSE_BAKE=true.
|
||||
#0 building with "desktop-linux" instance using docker driver
|
||||
|
||||
#1 [migrate internal] load build definition from Dockerfile
|
||||
#1 transferring dockerfile: 1.11kB done
|
||||
#1 DONE 0.0s
|
||||
|
||||
#2 [migrate internal] load metadata for docker.io/library/golang:1.24.4-alpine3.22
|
||||
#2 DONE 0.0s
|
||||
|
||||
#3 [migrate internal] load metadata for docker.io/library/alpine:3.22.1
|
||||
#3 DONE 0.2s
|
||||
|
||||
#4 [migrate internal] load .dockerignore
|
||||
#4 transferring context: 196B done
|
||||
#4 DONE 0.0s
|
||||
|
||||
#5 [migrate stage-2 1/4] FROM docker.io/library/alpine:3.22.1@sha256:4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8c44de311d1
|
||||
#5 resolve docker.io/library/alpine:3.22.1@sha256:4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8c44de311d1 0.0s done
|
||||
#5 DONE 0.0s
|
||||
|
||||
#6 [migrate build 1/7] FROM docker.io/library/golang:1.24.4-alpine3.22@sha256:68932fa6d4d4059845c8f40ad7e654e626f3ebd3706eef7846f319293ab5cb7a
|
||||
#6 resolve docker.io/library/golang:1.24.4-alpine3.22@sha256:68932fa6d4d4059845c8f40ad7e654e626f3ebd3706eef7846f319293ab5cb7a 0.0s done
|
||||
#6 DONE 0.0s
|
||||
|
||||
#7 [migrate internal] load build context
|
||||
#7 transferring context: 1.25kB done
|
||||
#7 DONE 0.0s
|
||||
|
||||
#8 [migrate build 5/7] COPY cmd/ ./cmd/
|
||||
#8 CACHED
|
||||
|
||||
#9 [migrate build 7/7] RUN --mount=type=cache,target=/go/pkg/mod CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/messenger ./cmd/server
|
||||
#9 CACHED
|
||||
|
||||
#10 [migrate build 4/7] RUN --mount=type=cache,target=/go/pkg/mod GODEBUG=http2client=0 GOPROXY="https://proxy.golang.org,direct" go mod download
|
||||
#10 CACHED
|
||||
|
||||
#11 [migrate stage-2 2/4] RUN apk add --no-cache libwebp-tools
|
||||
#11 CACHED
|
||||
|
||||
#12 [migrate build 3/7] COPY go.mod go.sum ./
|
||||
#12 CACHED
|
||||
|
||||
#13 [migrate build 6/7] COPY internal/ ./internal/
|
||||
#13 CACHED
|
||||
|
||||
#14 [migrate build 2/7] WORKDIR /src
|
||||
#14 CACHED
|
||||
|
||||
#15 [migrate stage-2 3/4] RUN addgroup -g 10001 app && adduser -D -u 10001 -G app app
|
||||
#15 CACHED
|
||||
|
||||
#16 [migrate stage-2 4/4] COPY --from=build /out/messenger /usr/local/bin/messenger
|
||||
#16 CACHED
|
||||
|
||||
#17 [migrate] exporting to image
|
||||
#17 exporting layers done
|
||||
#17 exporting manifest sha256:6b25d5f929665fec358139c521f8f1f068c1e27e16793588a46da6d6ff3e2f50 done
|
||||
#17 exporting config sha256:18eeea0513813c6c8c8fa55c46714c2de772d841c886a798f1d44f6b5940e97a done
|
||||
#17 exporting attestation manifest sha256:509e9ee6aeb2babc7c413c126b2bad6f9315007f7650fe6046c88a5852fc7e4a done
|
||||
#17 exporting manifest list sha256:d21bed98319478b55240a42810b6b44f752bb2a01a38980ddcaad6d7a55b7e29 done
|
||||
#17 naming to docker.io/library/mtusi-messenger:lab5 done
|
||||
#17 unpacking to docker.io/library/mtusi-messenger:lab5 done
|
||||
#17 DONE 0.0s
|
||||
|
||||
#18 [migrate] resolving provenance for metadata file
|
||||
#18 DONE 0.0s
|
||||
migrate Built
|
||||
Container mtusi-lab5-kraykin-postgres-1 Running
|
||||
Container mtusi-lab5-kraykin-migrate-1 Created
|
||||
Container mtusi-lab5-kraykin-migrate-1 Recreate
|
||||
Container mtusi-lab5-kraykin-migrate-1 Recreated
|
||||
Container mtusi-lab5-kraykin-postgres-1 Waiting
|
||||
Container mtusi-lab5-kraykin-postgres-1 Healthy
|
||||
Container mtusi-lab5-kraykin-migrate-1 Starting
|
||||
Container mtusi-lab5-kraykin-migrate-1 Started
|
||||
#0 building with "desktop-linux" instance using docker driver
|
||||
|
||||
#1 [tests internal] load build definition from Dockerfile
|
||||
#1 transferring dockerfile: 1.11kB done
|
||||
#1 DONE 0.0s
|
||||
|
||||
#2 [tests internal] load metadata for docker.io/library/golang:1.24.4-alpine3.22
|
||||
#2 DONE 0.0s
|
||||
|
||||
#3 [tests internal] load .dockerignore
|
||||
#3 transferring context: 196B done
|
||||
#3 DONE 0.0s
|
||||
|
||||
#4 [tests build 1/7] FROM docker.io/library/golang:1.24.4-alpine3.22@sha256:68932fa6d4d4059845c8f40ad7e654e626f3ebd3706eef7846f319293ab5cb7a
|
||||
#4 resolve docker.io/library/golang:1.24.4-alpine3.22@sha256:68932fa6d4d4059845c8f40ad7e654e626f3ebd3706eef7846f319293ab5cb7a done
|
||||
#4 DONE 0.0s
|
||||
|
||||
#5 [tests internal] load build context
|
||||
#5 transferring context: 1.25kB done
|
||||
#5 DONE 0.0s
|
||||
|
||||
#6 [tests build 2/7] WORKDIR /src
|
||||
#6 CACHED
|
||||
|
||||
#7 [tests build 4/7] RUN --mount=type=cache,target=/go/pkg/mod GODEBUG=http2client=0 GOPROXY="https://proxy.golang.org,direct" go mod download
|
||||
#7 CACHED
|
||||
|
||||
#8 [tests build 6/7] COPY internal/ ./internal/
|
||||
#8 CACHED
|
||||
|
||||
#9 [tests build 3/7] COPY go.mod go.sum ./
|
||||
#9 CACHED
|
||||
|
||||
#10 [tests build 5/7] COPY cmd/ ./cmd/
|
||||
#10 CACHED
|
||||
|
||||
#11 [tests build 7/7] RUN --mount=type=cache,target=/go/pkg/mod CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/messenger ./cmd/server
|
||||
#11 CACHED
|
||||
|
||||
#12 [tests tests 1/2] RUN apk add --no-cache gcc musl-dev libwebp-tools
|
||||
#12 0.120 fetch https://dl-cdn.alpinelinux.org/alpine/v3.22/main/aarch64/APKINDEX.tar.gz
|
||||
#12 0.856 fetch https://dl-cdn.alpinelinux.org/alpine/v3.22/community/aarch64/APKINDEX.tar.gz
|
||||
#12 4.725 (1/22) Upgrading musl (1.2.5-r10 -> 1.2.5-r13)
|
||||
#12 7.461 (2/22) Installing libgcc (14.2.0-r6)
|
||||
#12 7.833 (3/22) Installing jansson (2.14.1-r0)
|
||||
#12 8.102 (4/22) Installing libstdc++ (14.2.0-r6)
|
||||
#12 12.96 (5/22) Installing zstd-libs (1.5.7-r0)
|
||||
#12 15.02 (6/22) Installing binutils (2.44-r3)
|
||||
#12 38.37 (7/22) Installing libgomp (14.2.0-r6)
|
||||
#12 39.39 (8/22) Installing libatomic (14.2.0-r6)
|
||||
#12 39.56 (9/22) Installing gmp (6.3.0-r3)
|
||||
#12 41.05 (10/22) Installing isl26 (0.26-r1)
|
||||
#12 47.17 (11/22) Installing mpfr4 (4.2.1_p1-r0)
|
||||
#12 48.99 (12/22) Installing mpc1 (1.3.1-r1)
|
||||
#12 49.27 (13/22) Installing gcc (14.2.0-r6)
|
||||
#12 549.7 (14/22) Installing giflib (5.2.2-r2)
|
||||
#12 549.8 (15/22) Installing libjpeg-turbo (3.1.0-r0)
|
||||
#12 551.1 (16/22) Installing libpng (1.6.59-r0)
|
||||
#12 551.6 (17/22) Installing libsharpyuv (1.5.0-r0)
|
||||
#12 551.7 (18/22) Installing libwebp (1.5.0-r0)
|
||||
#12 552.7 (19/22) Installing libwebpdemux (1.5.0-r0)
|
||||
#12 552.8 (20/22) Installing libwebpmux (1.5.0-r0)
|
||||
#12 553.0 (21/22) Installing libwebp-tools (1.5.0-r0)
|
||||
#12 553.6 (22/22) Installing musl-dev (1.2.5-r13)
|
||||
#12 566.9 Executing busybox-1.37.0-r18.trigger
|
||||
#12 566.9 OK: 165 MiB in 38 packages
|
||||
#12 DONE 567.0s
|
||||
|
||||
#13 [tests tests 2/2] RUN --mount=type=cache,target=/go/pkg/mod mkdir -p /opt/gomod && cp -a /go/pkg/mod/. /opt/gomod/
|
||||
#13 DONE 1.6s
|
||||
|
||||
#14 [tests] exporting to image
|
||||
#14 exporting layers
|
||||
#14 exporting layers 5.2s done
|
||||
#14 exporting manifest sha256:a5c10d2aa2acc1aa68b58ccfaedf17a809a4f8fa4110e38942ece466352e58b4 done
|
||||
#14 exporting config sha256:be884776181b311e560acc8aec000173c5624f9d519c4f00c8f85fc1b772e223 done
|
||||
#14 exporting attestation manifest sha256:319b3e1cb5b467ca3f623126ca4de35d2d352bf4913ee20aa56a053708f026b3 0.0s done
|
||||
#14 exporting manifest list sha256:32e3bd7b054feff9a5ceb8976172b23607d1f9158d9bb8d175dad01124ed7bfe done
|
||||
#14 naming to docker.io/library/mtusi-messenger-tests:lab5 done
|
||||
#14 unpacking to docker.io/library/mtusi-messenger-tests:lab5
|
||||
#14 unpacking to docker.io/library/mtusi-messenger-tests:lab5 2.0s done
|
||||
#14 DONE 7.2s
|
||||
|
||||
#15 [tests] resolving provenance for metadata file
|
||||
#15 DONE 0.0s
|
||||
? mtusi/messenger/cmd/server [no test files]
|
||||
? mtusi/messenger/internal/database [no test files]
|
||||
=== RUN TestDatabaseConcurrentHTTP
|
||||
database_test.go:162: 100 confirmed messages from 10 clients through real HTTP and PostgreSQL; race detector enabled
|
||||
--- PASS: TestDatabaseConcurrentHTTP (1.69s)
|
||||
--- PASS: TestDatabaseConcurrentHTTP (1.75s)
|
||||
=== RUN TestPasswordFullUnicodeRange
|
||||
--- PASS: TestPasswordFullUnicodeRange (2.14s)
|
||||
--- PASS: TestPasswordFullUnicodeRange (2.12s)
|
||||
=== RUN TestTransformFailureClassification
|
||||
--- PASS: TestTransformFailureClassification (0.00s)
|
||||
=== RUN TestFitFloorNoUpscale
|
||||
--- PASS: TestFitFloorNoUpscale (0.00s)
|
||||
=== RUN TestTransformAlphaAndEXIF
|
||||
--- PASS: TestTransformAlphaAndEXIF (1.39s)
|
||||
--- PASS: TestTransformAlphaAndEXIF (0.25s)
|
||||
PASS
|
||||
ok mtusi/messenger/internal/messenger 6.247s
|
||||
ok mtusi/messenger/internal/messenger 5.161s
|
||||
|
||||
+24
-31
@@ -4,12 +4,12 @@
|
||||
{
|
||||
"service": "api",
|
||||
"name": "/mtusi-lab5-kraykin-api-3",
|
||||
"alias": "f2baf50a05e1",
|
||||
"alias": "9fcdf8ad0603",
|
||||
"image": "mtusi-messenger:lab5",
|
||||
"image_id": "sha256:033d93df8f2079dcce2716e5cc7d97e22fac1092ed299c04f8002eca730a0f1e",
|
||||
"image_id": "sha256:c99e8f8faa79ad809301fef274802cbaac38e84e89bf91f8eaba8250edeae5ea",
|
||||
"user": "10001:10001",
|
||||
"pid1_path": "/usr/local/bin/messenger",
|
||||
"started_at": "2026-11-20T18:35:20.134094001Z",
|
||||
"started_at": "2026-11-20T19:45:06.310439134Z",
|
||||
"memory_limit_bytes": 805306368,
|
||||
"nano_cpus_limit": 1000000000,
|
||||
"published_ports": {
|
||||
@@ -27,12 +27,12 @@
|
||||
{
|
||||
"service": "api",
|
||||
"name": "/mtusi-lab5-kraykin-api-4",
|
||||
"alias": "73a213d6be45",
|
||||
"alias": "f33a60f7d635",
|
||||
"image": "mtusi-messenger:lab5",
|
||||
"image_id": "sha256:033d93df8f2079dcce2716e5cc7d97e22fac1092ed299c04f8002eca730a0f1e",
|
||||
"image_id": "sha256:c99e8f8faa79ad809301fef274802cbaac38e84e89bf91f8eaba8250edeae5ea",
|
||||
"user": "10001:10001",
|
||||
"pid1_path": "/usr/local/bin/messenger",
|
||||
"started_at": "2026-11-20T18:35:28.062023797Z",
|
||||
"started_at": "2026-11-20T19:45:06.377709092Z",
|
||||
"memory_limit_bytes": 805306368,
|
||||
"nano_cpus_limit": 1000000000,
|
||||
"published_ports": {
|
||||
@@ -40,11 +40,11 @@
|
||||
},
|
||||
"health": "healthy",
|
||||
"mount_targets": [
|
||||
"/run/secrets/s3_secret_access_key",
|
||||
"/run/secrets/database_url",
|
||||
"/run/secrets/cache_url",
|
||||
"/run/secrets/cursor_key",
|
||||
"/run/secrets/s3_access_key_id"
|
||||
"/run/secrets/s3_access_key_id",
|
||||
"/run/secrets/s3_secret_access_key"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -71,12 +71,12 @@
|
||||
{
|
||||
"service": "dispatcher",
|
||||
"name": "/mtusi-lab5-kraykin-dispatcher-1",
|
||||
"alias": "2781dab1bf31",
|
||||
"alias": "143bd2091931",
|
||||
"image": "mtusi-messenger:lab5",
|
||||
"image_id": "sha256:033d93df8f2079dcce2716e5cc7d97e22fac1092ed299c04f8002eca730a0f1e",
|
||||
"image_id": "sha256:c99e8f8faa79ad809301fef274802cbaac38e84e89bf91f8eaba8250edeae5ea",
|
||||
"user": "10001:10001",
|
||||
"pid1_path": "/usr/local/bin/messenger",
|
||||
"started_at": "2026-11-20T18:31:55.513529337Z",
|
||||
"started_at": "2026-11-20T19:45:06.247870508Z",
|
||||
"memory_limit_bytes": 134217728,
|
||||
"nano_cpus_limit": 250000000,
|
||||
"published_ports": {
|
||||
@@ -84,21 +84,21 @@
|
||||
},
|
||||
"health": "healthy",
|
||||
"mount_targets": [
|
||||
"/run/secrets/database_url",
|
||||
"/run/secrets/broker_url",
|
||||
"/run/secrets/s3_access_key_id",
|
||||
"/run/secrets/s3_secret_access_key",
|
||||
"/run/secrets/database_url"
|
||||
"/run/secrets/s3_secret_access_key"
|
||||
]
|
||||
},
|
||||
{
|
||||
"service": "housekeeping",
|
||||
"name": "/mtusi-lab5-kraykin-housekeeping-1",
|
||||
"alias": "3af7f34eee90",
|
||||
"alias": "5aaadf8c620e",
|
||||
"image": "mtusi-messenger:lab5",
|
||||
"image_id": "sha256:033d93df8f2079dcce2716e5cc7d97e22fac1092ed299c04f8002eca730a0f1e",
|
||||
"image_id": "sha256:c99e8f8faa79ad809301fef274802cbaac38e84e89bf91f8eaba8250edeae5ea",
|
||||
"user": "10001:10001",
|
||||
"pid1_path": "/usr/local/bin/messenger",
|
||||
"started_at": "2026-11-20T18:31:55.591483212Z",
|
||||
"started_at": "2026-11-20T19:45:06.305480592Z",
|
||||
"memory_limit_bytes": 134217728,
|
||||
"nano_cpus_limit": 250000000,
|
||||
"published_ports": {
|
||||
@@ -172,9 +172,9 @@
|
||||
},
|
||||
"health": "healthy",
|
||||
"mount_targets": [
|
||||
"/data",
|
||||
"/run/secrets/s3_root_user",
|
||||
"/run/secrets/s3_root_password"
|
||||
"/run/secrets/s3_root_password",
|
||||
"/data"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -193,19 +193,19 @@
|
||||
},
|
||||
"health": null,
|
||||
"mount_targets": [
|
||||
"/data",
|
||||
"/run/secrets/valkey_config"
|
||||
"/run/secrets/valkey_config",
|
||||
"/data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"service": "worker",
|
||||
"name": "/mtusi-lab5-kraykin-worker-1",
|
||||
"alias": "3937bad317b9",
|
||||
"alias": "e045cc8a7994",
|
||||
"image": "mtusi-messenger:lab5",
|
||||
"image_id": "sha256:033d93df8f2079dcce2716e5cc7d97e22fac1092ed299c04f8002eca730a0f1e",
|
||||
"image_id": "sha256:c99e8f8faa79ad809301fef274802cbaac38e84e89bf91f8eaba8250edeae5ea",
|
||||
"user": "10001:10001",
|
||||
"pid1_path": "/usr/local/bin/messenger",
|
||||
"started_at": "2026-11-20T18:31:55.590725254Z",
|
||||
"started_at": "2026-11-20T19:45:06.306100384Z",
|
||||
"memory_limit_bytes": 1073741824,
|
||||
"nano_cpus_limit": 1000000000,
|
||||
"published_ports": {
|
||||
@@ -225,12 +225,5 @@
|
||||
"full_page_writes=on",
|
||||
"max_connections=100",
|
||||
"synchronous_commit=on"
|
||||
],
|
||||
"docker_vm": {
|
||||
"architecture": "aarch64",
|
||||
"cpus": 14,
|
||||
"memory_bytes": 8217473024,
|
||||
"engine": "28.1.1",
|
||||
"compose": "2.35.1-desktop.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+265
-39
@@ -1,19 +1,245 @@
|
||||
Container mtusi-lab5-kraykin-s3-1 Running
|
||||
Compose can now delegate builds to bake for better performance.
|
||||
To do so, set COMPOSE_BAKE=true.
|
||||
#0 building with "desktop-linux" instance using docker driver
|
||||
|
||||
#1 [migrate internal] load build definition from Dockerfile
|
||||
#1 transferring dockerfile: 1.11kB done
|
||||
#1 DONE 0.0s
|
||||
|
||||
#2 [migrate internal] load metadata for docker.io/library/golang:1.24.4-alpine3.22
|
||||
#2 DONE 0.0s
|
||||
|
||||
#3 [migrate internal] load metadata for docker.io/library/alpine:3.22.1
|
||||
#3 DONE 0.3s
|
||||
|
||||
#4 [migrate stage-2 1/4] FROM docker.io/library/alpine:3.22.1@sha256:4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8c44de311d1
|
||||
#4 resolve docker.io/library/alpine:3.22.1@sha256:4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8c44de311d1 done
|
||||
#4 DONE 0.0s
|
||||
|
||||
#5 [migrate internal] load .dockerignore
|
||||
#5 transferring context: 196B done
|
||||
#5 DONE 0.0s
|
||||
|
||||
#6 [migrate internal] load build context
|
||||
#6 DONE 0.0s
|
||||
|
||||
#7 [migrate build 1/7] FROM docker.io/library/golang:1.24.4-alpine3.22@sha256:68932fa6d4d4059845c8f40ad7e654e626f3ebd3706eef7846f319293ab5cb7a
|
||||
#7 resolve docker.io/library/golang:1.24.4-alpine3.22@sha256:68932fa6d4d4059845c8f40ad7e654e626f3ebd3706eef7846f319293ab5cb7a
|
||||
#7 resolve docker.io/library/golang:1.24.4-alpine3.22@sha256:68932fa6d4d4059845c8f40ad7e654e626f3ebd3706eef7846f319293ab5cb7a 2.1s done
|
||||
#7 DONE 2.1s
|
||||
|
||||
#6 [migrate internal] load build context
|
||||
#6 transferring context: 9.92kB done
|
||||
#6 DONE 0.0s
|
||||
|
||||
#8 [migrate build 3/7] COPY go.mod go.sum ./
|
||||
#8 CACHED
|
||||
|
||||
#9 [migrate build 4/7] RUN --mount=type=cache,target=/go/pkg/mod GODEBUG=http2client=0 GOPROXY="https://proxy.golang.org,direct" go mod download
|
||||
#9 CACHED
|
||||
|
||||
#10 [migrate build 2/7] WORKDIR /src
|
||||
#10 CACHED
|
||||
|
||||
#11 [migrate build 5/7] COPY cmd/ ./cmd/
|
||||
#11 CACHED
|
||||
|
||||
#12 [migrate build 6/7] COPY internal/ ./internal/
|
||||
#12 DONE 0.0s
|
||||
|
||||
#13 [migrate build 7/7] RUN --mount=type=cache,target=/go/pkg/mod CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/messenger ./cmd/server
|
||||
#13 DONE 11.2s
|
||||
|
||||
#14 [migrate stage-2 2/4] RUN apk add --no-cache libwebp-tools
|
||||
#14 CACHED
|
||||
|
||||
#15 [migrate stage-2 3/4] RUN addgroup -g 10001 app && adduser -D -u 10001 -G app app
|
||||
#15 CACHED
|
||||
|
||||
#16 [migrate stage-2 4/4] COPY --from=build /out/messenger /usr/local/bin/messenger
|
||||
#16 DONE 0.0s
|
||||
|
||||
#17 [migrate] exporting to image
|
||||
#17 exporting layers
|
||||
#17 exporting layers 0.3s done
|
||||
#17 exporting manifest sha256:74ca64f8f1ccbda510c4342ca0cb5801d0410c98c98dc583e9edab6a4fa354f2
|
||||
#17 exporting manifest sha256:74ca64f8f1ccbda510c4342ca0cb5801d0410c98c98dc583e9edab6a4fa354f2 done
|
||||
#17 exporting config sha256:aaa14b42aada277f395995e7435bc78509022d32cf71468d26a3aa4d42742a7e done
|
||||
#17 exporting attestation manifest sha256:d17fbf66047537fbcab6a862bba0ce258878535660b34ff1f2778c4d691500e6 0.0s done
|
||||
#17 exporting manifest list sha256:f82726c3bf2e84b42cf10844dedf3e32ec03646486e571a35f9405b984c3c6fc done
|
||||
#17 naming to docker.io/library/mtusi-messenger:lab5 done
|
||||
#17 unpacking to docker.io/library/mtusi-messenger:lab5 0.0s done
|
||||
#17 DONE 0.4s
|
||||
|
||||
#18 [migrate] resolving provenance for metadata file
|
||||
#18 DONE 0.0s
|
||||
|
||||
#19 [worker internal] load build definition from Dockerfile
|
||||
#19 transferring dockerfile: 1.11kB done
|
||||
#19 DONE 0.0s
|
||||
|
||||
#20 [api internal] load build definition from Dockerfile
|
||||
#20 transferring dockerfile: 1.11kB done
|
||||
#20 DONE 0.0s
|
||||
|
||||
#21 [housekeeping internal] load build definition from Dockerfile
|
||||
#21 transferring dockerfile: 1.11kB done
|
||||
#21 DONE 0.0s
|
||||
|
||||
#22 [dispatcher internal] load build definition from Dockerfile
|
||||
#22 transferring dockerfile: 1.11kB done
|
||||
#22 DONE 0.0s
|
||||
|
||||
#3 [dispatcher internal] load metadata for docker.io/library/alpine:3.22.1
|
||||
#3 ...
|
||||
|
||||
#2 [housekeeping internal] load metadata for docker.io/library/golang:1.24.4-alpine3.22
|
||||
#2 DONE 0.2s
|
||||
|
||||
#3 [dispatcher internal] load metadata for docker.io/library/alpine:3.22.1
|
||||
#3 DONE 1.3s
|
||||
|
||||
#23 [api internal] load .dockerignore
|
||||
#23 transferring context: 196B done
|
||||
#23 DONE 0.0s
|
||||
|
||||
#24 [housekeeping internal] load .dockerignore
|
||||
#24 transferring context: 196B done
|
||||
#24 DONE 0.0s
|
||||
|
||||
#25 [dispatcher internal] load .dockerignore
|
||||
#25 transferring context: 196B done
|
||||
#25 DONE 0.0s
|
||||
|
||||
#26 [worker internal] load .dockerignore
|
||||
#26 transferring context: 196B done
|
||||
#26 DONE 0.0s
|
||||
|
||||
#4 [api stage-2 1/4] FROM docker.io/library/alpine:3.22.1@sha256:4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8c44de311d1
|
||||
#4 resolve docker.io/library/alpine:3.22.1@sha256:4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8c44de311d1 0.0s done
|
||||
#4 DONE 0.0s
|
||||
|
||||
#7 [housekeeping build 1/7] FROM docker.io/library/golang:1.24.4-alpine3.22@sha256:68932fa6d4d4059845c8f40ad7e654e626f3ebd3706eef7846f319293ab5cb7a
|
||||
#7 resolve docker.io/library/golang:1.24.4-alpine3.22@sha256:68932fa6d4d4059845c8f40ad7e654e626f3ebd3706eef7846f319293ab5cb7a 0.0s done
|
||||
#7 DONE 2.1s
|
||||
|
||||
#27 [api internal] load build context
|
||||
#27 transferring context: 1.30kB done
|
||||
#27 DONE 0.0s
|
||||
|
||||
#28 [housekeeping internal] load build context
|
||||
#28 transferring context: 9.92kB done
|
||||
#28 DONE 0.0s
|
||||
|
||||
#29 [worker internal] load build context
|
||||
#29 transferring context: 9.92kB done
|
||||
#29 DONE 0.0s
|
||||
|
||||
#30 [dispatcher internal] load build context
|
||||
#30 transferring context: 9.92kB done
|
||||
#30 DONE 0.0s
|
||||
|
||||
#31 [api build 5/7] COPY cmd/ ./cmd/
|
||||
#31 CACHED
|
||||
|
||||
#32 [api build 3/7] COPY go.mod go.sum ./
|
||||
#32 CACHED
|
||||
|
||||
#33 [api build 7/7] RUN --mount=type=cache,target=/go/pkg/mod CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/messenger ./cmd/server
|
||||
#33 CACHED
|
||||
|
||||
#34 [api build 6/7] COPY internal/ ./internal/
|
||||
#34 CACHED
|
||||
|
||||
#10 [api build 2/7] WORKDIR /src
|
||||
#10 CACHED
|
||||
|
||||
#35 [api build 4/7] RUN --mount=type=cache,target=/go/pkg/mod GODEBUG=http2client=0 GOPROXY="https://proxy.golang.org,direct" go mod download
|
||||
#35 CACHED
|
||||
|
||||
#14 [dispatcher stage-2 2/4] RUN apk add --no-cache libwebp-tools
|
||||
#14 CACHED
|
||||
|
||||
#15 [dispatcher stage-2 3/4] RUN addgroup -g 10001 app && adduser -D -u 10001 -G app app
|
||||
#15 CACHED
|
||||
|
||||
#36 [dispatcher stage-2 4/4] COPY --from=build /out/messenger /usr/local/bin/messenger
|
||||
#36 CACHED
|
||||
|
||||
#37 [dispatcher] exporting to image
|
||||
#37 exporting layers done
|
||||
#37 exporting manifest sha256:37933fdac941597c967c906c4061dd8b0a8ce7b4669b2e4e2f666426545e4208
|
||||
#37 exporting manifest sha256:37933fdac941597c967c906c4061dd8b0a8ce7b4669b2e4e2f666426545e4208 0.0s done
|
||||
#37 exporting config sha256:000cacf928e2b797dbb0661bfa4b1754e572779e5a4ebb9d4fd97459eee00ab8 0.0s done
|
||||
#37 exporting attestation manifest sha256:eb03c27127b3592cd8ac241f7683c8ef0cfc631c9f8c01697948f064b143d073
|
||||
#37 exporting attestation manifest sha256:eb03c27127b3592cd8ac241f7683c8ef0cfc631c9f8c01697948f064b143d073 0.0s done
|
||||
#37 exporting manifest list sha256:c99e8f8faa79ad809301fef274802cbaac38e84e89bf91f8eaba8250edeae5ea 0.0s done
|
||||
#37 naming to docker.io/library/mtusi-messenger:lab5 done
|
||||
#37 unpacking to docker.io/library/mtusi-messenger:lab5 done
|
||||
#37 DONE 0.2s
|
||||
|
||||
#38 [api] exporting to image
|
||||
#38 exporting layers done
|
||||
#38 exporting manifest sha256:6e36459b898b2aaaa269e9c92fc7990ba23deff59948882cc514cc236bc03984 done
|
||||
#38 exporting config sha256:30310d416e83728d91b84a11461f00160e8401c4bf4593db2a1e0312975629e3 0.0s done
|
||||
#38 exporting attestation manifest sha256:598190941da6fa0ffa671ea41fa58b20cea39672b6834e6f50ca92df38d728e8 0.0s done
|
||||
#38 exporting manifest list sha256:61c0c89cb293272cb9a336ca4a8299e3aeb50e7ccf9f9519844e62f86107a3ee 0.0s done
|
||||
#38 naming to docker.io/library/mtusi-messenger:lab5 done
|
||||
#38 unpacking to docker.io/library/mtusi-messenger:lab5 0.0s done
|
||||
#38 DONE 0.2s
|
||||
|
||||
#39 [worker] exporting to image
|
||||
#39 exporting layers done
|
||||
#39 exporting manifest sha256:0f34703e5afafe40d98d3eab1c01b118399d8035639353de9b571b24ab612686 0.0s done
|
||||
#39 exporting config sha256:d18c634d53fa1f0e8b3ef8daa5589a07ffdd1dbe35ab1f0e987aa256b566f80f 0.0s done
|
||||
#39 exporting attestation manifest sha256:d0cbca3816d565931f3b73163ffb1be9fb9f06d69205348be518b637cf4cc503 0.0s done
|
||||
#39 exporting manifest list sha256:c7312468c1c3e38a5699dae3bed92d992c388402193ae23b315f190f394c78a6 0.0s done
|
||||
#39 naming to docker.io/library/mtusi-messenger:lab5 done
|
||||
#39 unpacking to docker.io/library/mtusi-messenger:lab5 done
|
||||
#39 DONE 0.2s
|
||||
|
||||
#40 [housekeeping] exporting to image
|
||||
#40 exporting layers done
|
||||
#40 exporting manifest sha256:637d1992903591dbed41af65263b71974ded77af9aad1bee49ca2d5ec1c7039d 0.0s done
|
||||
#40 exporting config sha256:c15291f20d0ece057c8c5be93cec6105efd3c44f7a20fdb05618f3e22f251370 0.0s done
|
||||
#40 exporting attestation manifest sha256:7bad7626422d7f8f97fec248243e9a380754b78eeece259af5a15f325da256df 0.0s done
|
||||
#40 exporting manifest list sha256:24fc59d5434ab9de6b347648b1f536b799572e83d5b7857494ae356d0b4554e0 0.0s done
|
||||
#40 naming to docker.io/library/mtusi-messenger:lab5 done
|
||||
#40 unpacking to docker.io/library/mtusi-messenger:lab5 done
|
||||
#40 DONE 0.2s
|
||||
|
||||
#41 [api] resolving provenance for metadata file
|
||||
#41 DONE 0.1s
|
||||
|
||||
#42 [housekeeping] resolving provenance for metadata file
|
||||
#42 DONE 0.0s
|
||||
|
||||
#43 [dispatcher] resolving provenance for metadata file
|
||||
#43 DONE 0.1s
|
||||
|
||||
#44 [worker] resolving provenance for metadata file
|
||||
#44 DONE 0.0s
|
||||
api Built
|
||||
dispatcher Built
|
||||
housekeeping Built
|
||||
migrate Built
|
||||
worker Built
|
||||
Container mtusi-lab5-kraykin-broker-1 Running
|
||||
Container mtusi-lab5-kraykin-postgres-1 Running
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Created
|
||||
Container mtusi-lab5-kraykin-s3-1 Running
|
||||
Container mtusi-lab5-kraykin-valkey-1 Running
|
||||
Container mtusi-lab5-kraykin-migrate-1 Recreate
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Created
|
||||
Container mtusi-lab5-kraykin-migrate-1 Recreated
|
||||
Container mtusi-lab5-kraykin-worker-1 Recreate
|
||||
Container mtusi-lab5-kraykin-housekeeping-1 Recreate
|
||||
Container mtusi-lab5-kraykin-dispatcher-1 Recreate
|
||||
Container mtusi-lab5-kraykin-api-2 Recreate
|
||||
Container mtusi-lab5-kraykin-api-1 Recreate
|
||||
Container mtusi-lab5-kraykin-worker-1 Recreate
|
||||
Container mtusi-lab5-kraykin-api-4 Recreate
|
||||
Container mtusi-lab5-kraykin-api-3 Recreate
|
||||
Container mtusi-lab5-kraykin-dispatcher-1 Recreated
|
||||
Container mtusi-lab5-kraykin-housekeeping-1 Recreated
|
||||
Container mtusi-lab5-kraykin-api-2 Recreated
|
||||
Container mtusi-lab5-kraykin-api-1 Recreated
|
||||
Container mtusi-lab5-kraykin-api-3 Recreated
|
||||
Container mtusi-lab5-kraykin-api-4 Recreated
|
||||
Container mtusi-lab5-kraykin-lb-1 Running
|
||||
Container mtusi-lab5-kraykin-worker-1 Recreated
|
||||
Container mtusi-lab5-kraykin-postgres-1 Waiting
|
||||
@@ -22,57 +248,57 @@
|
||||
Container mtusi-lab5-kraykin-migrate-1 Starting
|
||||
Container mtusi-lab5-kraykin-s3-1 Healthy
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Starting
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Started
|
||||
Container mtusi-lab5-kraykin-migrate-1 Started
|
||||
Container mtusi-lab5-kraykin-migrate-1 Waiting
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Waiting
|
||||
Container mtusi-lab5-kraykin-migrate-1 Waiting
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Started
|
||||
Container mtusi-lab5-kraykin-migrate-1 Waiting
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Waiting
|
||||
Container mtusi-lab5-kraykin-migrate-1 Waiting
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Waiting
|
||||
Container mtusi-lab5-kraykin-migrate-1 Waiting
|
||||
Container mtusi-lab5-kraykin-migrate-1 Exited
|
||||
Container mtusi-lab5-kraykin-migrate-1 Exited
|
||||
Container mtusi-lab5-kraykin-migrate-1 Exited
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Waiting
|
||||
Container mtusi-lab5-kraykin-migrate-1 Exited
|
||||
Container mtusi-lab5-kraykin-dispatcher-1 Starting
|
||||
Container mtusi-lab5-kraykin-dispatcher-1 Started
|
||||
Container mtusi-lab5-kraykin-migrate-1 Exited
|
||||
Container mtusi-lab5-kraykin-migrate-1 Exited
|
||||
Container mtusi-lab5-kraykin-migrate-1 Exited
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Exited
|
||||
Container mtusi-lab5-kraykin-api-1 Starting
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Exited
|
||||
Container mtusi-lab5-kraykin-api-3 Starting
|
||||
Container mtusi-lab5-kraykin-worker-1 Starting
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Exited
|
||||
Container mtusi-lab5-kraykin-housekeeping-1 Starting
|
||||
Container mtusi-lab5-kraykin-api-1 Started
|
||||
Container mtusi-lab5-kraykin-api-2 Starting
|
||||
Container mtusi-lab5-kraykin-dispatcher-1 Started
|
||||
Container mtusi-lab5-kraykin-api-3 Started
|
||||
Container mtusi-lab5-kraykin-api-4 Starting
|
||||
Container mtusi-lab5-kraykin-housekeeping-1 Started
|
||||
Container mtusi-lab5-kraykin-worker-1 Started
|
||||
Container mtusi-lab5-kraykin-api-2 Started
|
||||
Container mtusi-lab5-kraykin-api-1 Waiting
|
||||
Container mtusi-lab5-kraykin-api-2 Waiting
|
||||
Container mtusi-lab5-kraykin-api-1 Healthy
|
||||
Container mtusi-lab5-kraykin-api-2 Healthy
|
||||
Container mtusi-lab5-kraykin-s3-1 Waiting
|
||||
Container mtusi-lab5-kraykin-worker-1 Waiting
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Waiting
|
||||
Container mtusi-lab5-kraykin-lb-1 Waiting
|
||||
Container mtusi-lab5-kraykin-housekeeping-1 Waiting
|
||||
Container mtusi-lab5-kraykin-api-1 Waiting
|
||||
Container mtusi-lab5-kraykin-api-2 Waiting
|
||||
Container mtusi-lab5-kraykin-api-4 Started
|
||||
Container mtusi-lab5-kraykin-api-3 Waiting
|
||||
Container mtusi-lab5-kraykin-api-4 Waiting
|
||||
Container mtusi-lab5-kraykin-api-3 Healthy
|
||||
Container mtusi-lab5-kraykin-api-4 Healthy
|
||||
Container mtusi-lab5-kraykin-broker-1 Waiting
|
||||
Container mtusi-lab5-kraykin-dispatcher-1 Waiting
|
||||
Container mtusi-lab5-kraykin-valkey-1 Waiting
|
||||
Container mtusi-lab5-kraykin-postgres-1 Waiting
|
||||
Container mtusi-lab5-kraykin-migrate-1 Waiting
|
||||
Container mtusi-lab5-kraykin-housekeeping-1 Waiting
|
||||
Container mtusi-lab5-kraykin-lb-1 Waiting
|
||||
Container mtusi-lab5-kraykin-s3-1 Waiting
|
||||
Container mtusi-lab5-kraykin-valkey-1 Waiting
|
||||
Container mtusi-lab5-kraykin-dispatcher-1 Waiting
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Waiting
|
||||
Container mtusi-lab5-kraykin-worker-1 Waiting
|
||||
Container mtusi-lab5-kraykin-api-3 Waiting
|
||||
Container mtusi-lab5-kraykin-api-4 Waiting
|
||||
Container mtusi-lab5-kraykin-postgres-1 Healthy
|
||||
Container mtusi-lab5-kraykin-broker-1 Healthy
|
||||
Container mtusi-lab5-kraykin-housekeeping-1 Healthy
|
||||
Container mtusi-lab5-kraykin-worker-1 Healthy
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Exited
|
||||
Container mtusi-lab5-kraykin-lb-1 Healthy
|
||||
Container mtusi-lab5-kraykin-migrate-1 Exited
|
||||
Container mtusi-lab5-kraykin-dispatcher-1 Healthy
|
||||
Container mtusi-lab5-kraykin-s3-1 Healthy
|
||||
Container mtusi-lab5-kraykin-valkey-1 Healthy
|
||||
Container mtusi-lab5-kraykin-migrate-1 Exited
|
||||
Container mtusi-lab5-kraykin-lb-1 Healthy
|
||||
Container mtusi-lab5-kraykin-housekeeping-1 Healthy
|
||||
Container mtusi-lab5-kraykin-s3-init-1 Exited
|
||||
Container mtusi-lab5-kraykin-worker-1 Healthy
|
||||
Container mtusi-lab5-kraykin-broker-1 Healthy
|
||||
Container mtusi-lab5-kraykin-api-1 Healthy
|
||||
Container mtusi-lab5-kraykin-api-2 Healthy
|
||||
Container mtusi-lab5-kraykin-api-3 Healthy
|
||||
Container mtusi-lab5-kraykin-api-4 Healthy
|
||||
|
||||
@@ -306,7 +306,8 @@ func (p *Pipeline) process(parent context.Context, j Job) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
var errInvalidImage = errors.New("invalid_image")
|
||||
var ErrInvalidImage = errors.New("invalid_image")
|
||||
var errInvalidImage = ErrInvalidImage
|
||||
|
||||
func resultPrefix(j Job) string {
|
||||
return "originals/" + j.AttachmentID + "/v" + strconv.Itoa(j.Version) + "/"
|
||||
@@ -346,10 +347,7 @@ func (p *Pipeline) perform(ctx context.Context, j Job, key, sha, contentType str
|
||||
// an orphan encoder outliving the transform deadline (Linux container only).
|
||||
configureChild(cmd)
|
||||
if e = cmd.Run(); e != nil {
|
||||
if transformCtx.Err() != nil {
|
||||
return nil, transformCtx.Err()
|
||||
}
|
||||
return nil, errInvalidImage
|
||||
return nil, classifyTransformFailure(transformCtx.Err(), e)
|
||||
}
|
||||
raw, e := os.ReadFile(filepath.Join(dir, "variants.json"))
|
||||
if e != nil {
|
||||
@@ -397,3 +395,15 @@ func faultPoint(point string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A killed/crashed encoder is not evidence of an invalid source image.
|
||||
func classifyTransformFailure(deadline, errorResult error) error {
|
||||
if deadline != nil {
|
||||
return deadline
|
||||
}
|
||||
var exited *exec.ExitError
|
||||
if errors.As(errorResult, &exited) && exited.ExitCode() == 65 {
|
||||
return ErrInvalidImage
|
||||
}
|
||||
return fmt.Errorf("transform temporarily unavailable")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package messenger
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"github.com/disintegration/imaging"
|
||||
"image"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// imaging handles JPEG APP1 orientation. PNG stores the same TIFF data in eXIf.
|
||||
// Read only inside the already capped upload, with bounds checks on every IFD.
|
||||
func pngOrientation(path string) int {
|
||||
f, e := os.Open(path)
|
||||
if e != nil {
|
||||
return 1
|
||||
}
|
||||
defer f.Close()
|
||||
if _, e = f.Seek(8, io.SeekStart); e != nil {
|
||||
return 1
|
||||
}
|
||||
for {
|
||||
var h [8]byte
|
||||
if _, e = io.ReadFull(f, h[:]); e != nil {
|
||||
return 1
|
||||
}
|
||||
n := binary.BigEndian.Uint32(h[:4])
|
||||
if n > maxUpload {
|
||||
return 1
|
||||
}
|
||||
if string(h[4:]) == "eXIf" {
|
||||
b := make([]byte, n)
|
||||
if _, e = io.ReadFull(f, b); e != nil {
|
||||
return 1
|
||||
}
|
||||
return tiffOrientation(b)
|
||||
}
|
||||
if string(h[4:]) == "IEND" {
|
||||
return 1
|
||||
}
|
||||
if _, e = f.Seek(int64(n)+4, io.SeekCurrent); e != nil {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
func tiffOrientation(b []byte) int {
|
||||
if len(b) < 8 {
|
||||
return 1
|
||||
}
|
||||
var order binary.ByteOrder
|
||||
switch string(b[:2]) {
|
||||
case "II":
|
||||
order = binary.LittleEndian
|
||||
case "MM":
|
||||
order = binary.BigEndian
|
||||
default:
|
||||
return 1
|
||||
}
|
||||
if order.Uint16(b[2:4]) != 42 {
|
||||
return 1
|
||||
}
|
||||
offset := uint64(order.Uint32(b[4:8]))
|
||||
if offset+2 > uint64(len(b)) {
|
||||
return 1
|
||||
}
|
||||
count := int(order.Uint16(b[offset : offset+2]))
|
||||
for i := 0; i < count; i++ {
|
||||
pos := offset + 2 + uint64(i)*12
|
||||
if pos+12 > uint64(len(b)) {
|
||||
return 1
|
||||
}
|
||||
entry := b[pos : pos+12]
|
||||
if order.Uint16(entry[:2]) == 0x112 && order.Uint16(entry[2:4]) == 3 && order.Uint32(entry[4:8]) == 1 {
|
||||
v := int(order.Uint16(entry[8:10]))
|
||||
if v >= 1 && v <= 8 {
|
||||
return v
|
||||
}
|
||||
return 1
|
||||
}
|
||||
}
|
||||
return 1
|
||||
}
|
||||
func orientPNG(img image.Image, orientation int) image.Image {
|
||||
switch orientation {
|
||||
case 2:
|
||||
return imaging.FlipH(img)
|
||||
case 3:
|
||||
return imaging.Rotate180(img)
|
||||
case 4:
|
||||
return imaging.FlipV(img)
|
||||
case 5:
|
||||
return imaging.Transpose(img)
|
||||
case 6:
|
||||
return imaging.Rotate270(img)
|
||||
case 7:
|
||||
return imaging.Transverse(img)
|
||||
case 8:
|
||||
return imaging.Rotate90(img)
|
||||
}
|
||||
return img
|
||||
}
|
||||
@@ -47,19 +47,23 @@ func Transform(input, dir string, versions ...int) error {
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
c, _, e := image.DecodeConfig(f)
|
||||
c, format, e := image.DecodeConfig(f)
|
||||
f.Close()
|
||||
if e != nil || c.Width < 1 || c.Height < 1 || int64(c.Width)*int64(c.Height) > maxPixels {
|
||||
return fmt.Errorf("invalid_image")
|
||||
return ErrInvalidImage
|
||||
}
|
||||
img, e := imaging.Open(input, imaging.AutoOrientation(true))
|
||||
if e != nil {
|
||||
return fmt.Errorf("invalid_image")
|
||||
return ErrInvalidImage
|
||||
}
|
||||
bounds := img.Bounds()
|
||||
var oriented image.Image = img
|
||||
if format == "png" {
|
||||
oriented = orientPNG(img, pngOrientation(input))
|
||||
}
|
||||
bounds := oriented.Bounds()
|
||||
white := image.NewNRGBA(bounds)
|
||||
draw.Draw(white, bounds, &image.Uniform{C: color.White}, image.Point{}, draw.Src)
|
||||
draw.Draw(white, bounds, img, bounds.Min, draw.Over)
|
||||
draw.Draw(white, bounds, oriented, bounds.Min, draw.Over)
|
||||
w, h := fitDimensions(bounds.Dx(), bounds.Dy(), 256)
|
||||
thumbnail := imaging.Resize(white, w, h, imaging.Lanczos)
|
||||
crop := imaging.Fill(white, 128, 128, imaging.Center, imaging.Lanczos)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package messenger
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os/exec"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTransformFailureClassification(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
command string
|
||||
invalid bool
|
||||
}{{"exit 65", true}, {"exit 2", false}, {"kill -KILL $$", false}} {
|
||||
e := exec.Command("sh", "-c", c.command).Run()
|
||||
if errors.Is(classifyTransformFailure(nil, e), ErrInvalidImage) != c.invalid {
|
||||
t.Fatalf("misclassified encoder termination %q", c.command)
|
||||
}
|
||||
}
|
||||
if !errors.Is(classifyTransformFailure(context.DeadlineExceeded, nil), context.DeadlineExceeded) {
|
||||
t.Fatal("deadline lost")
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package messenger
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"hash/crc32"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/jpeg"
|
||||
@@ -70,3 +71,48 @@ func TestTransformAlphaAndEXIF(t *testing.T) {
|
||||
t.Fatalf("EXIF ignored: %v", img.Bounds())
|
||||
}
|
||||
}
|
||||
|
||||
func TestPNGEXIFAndMalformedIFD(t *testing.T) {
|
||||
tiff := []byte{'I', 'I', 42, 0, 8, 0, 0, 0, 1, 0, 0x12, 1, 3, 0, 1, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0}
|
||||
if tiffOrientation(tiff) != 6 {
|
||||
t.Fatal("TIFF orientation")
|
||||
}
|
||||
for i := 0; i < len(tiff); i++ {
|
||||
_ = tiffOrientation(tiff[:i])
|
||||
}
|
||||
bad := append([]byte{}, tiff...)
|
||||
for i := 4; i < 8; i++ {
|
||||
bad[i] = 255
|
||||
}
|
||||
if tiffOrientation(bad) != 1 {
|
||||
t.Fatal("bad IFD offset")
|
||||
}
|
||||
var raw bytes.Buffer
|
||||
png.Encode(&raw, image.NewNRGBA(image.Rect(0, 0, 320, 200)))
|
||||
var chunk bytes.Buffer
|
||||
binary.Write(&chunk, binary.BigEndian, uint32(len(tiff)))
|
||||
chunk.WriteString("eXIf")
|
||||
chunk.Write(tiff)
|
||||
binary.Write(&chunk, binary.BigEndian, crc32.ChecksumIEEE(chunk.Bytes()[4:]))
|
||||
data := append(append(append([]byte{}, raw.Bytes()[:33]...), chunk.Bytes()...), raw.Bytes()[33:]...)
|
||||
dir := t.TempDir()
|
||||
input := filepath.Join(dir, "input.png")
|
||||
os.WriteFile(input, data, 0600)
|
||||
if pngOrientation(input) != 6 {
|
||||
t.Fatal("PNG eXIf orientation")
|
||||
}
|
||||
if _, e := exec.LookPath("cwebp"); e != nil {
|
||||
return
|
||||
}
|
||||
if e := Transform(input, dir); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
b, _ := os.ReadFile(filepath.Join(dir, "thumbnail"))
|
||||
img, e := jpeg.Decode(bytes.NewReader(b))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if img.Bounds().Dx() != 160 || img.Bounds().Dy() != 256 {
|
||||
t.Fatal("PNG orientation not applied", img.Bounds())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user