diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e40e09ec..7e065e41 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,7 +96,7 @@ jobs: steps: - uses: actions/checkout@v7.0.1 - - uses: jdx/mise-action@v5.4.0 + - uses: jdx/mise-action@v5.5.0 with: install_args: actionlint shellcheck github:standards-lab/claude-plugins @@ -115,7 +115,7 @@ jobs: steps: - uses: actions/checkout@v7.0.1 - - uses: jdx/mise-action@v5.4.0 + - uses: jdx/mise-action@v5.5.0 with: install_args: go golangci-lint @@ -152,7 +152,7 @@ jobs: if: hashFiles(format('tools/{0}/*.slnx', matrix.tool)) != '' run: sudo apt-get update && sudo apt-get install -y --no-install-recommends clang zlib1g-dev - - uses: jdx/mise-action@v5.4.0 + - uses: jdx/mise-action@v5.5.0 with: working_directory: tools/${{ matrix.tool }} @@ -195,7 +195,7 @@ jobs: steps: - uses: actions/checkout@v7.0.1 - - uses: jdx/mise-action@v5.4.0 + - uses: jdx/mise-action@v5.5.0 with: install_args: go @@ -224,7 +224,7 @@ jobs: - name: Install the NativeAOT prerequisites run: sudo apt-get update && sudo apt-get install -y --no-install-recommends clang zlib1g-dev - - uses: jdx/mise-action@v5.4.0 + - uses: jdx/mise-action@v5.5.0 with: working_directory: tools/ooxml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5c9139b5..b04221b5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -57,7 +57,7 @@ jobs: if: hashFiles(format('tools/{0}/*.slnx', needs.tag.outputs.format)) != '' run: sudo apt-get update && sudo apt-get install -y --no-install-recommends clang zlib1g-dev - - uses: jdx/mise-action@v5.4.0 + - uses: jdx/mise-action@v5.5.0 with: working_directory: tools/${{ needs.tag.outputs.format }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 125c714c..3cdcf4e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,30 @@ tool under `tools/` keeps its own. ## [Unreleased] +## [v0.13.0] - 2026-12-02 + +This release adds `route.MediaType`, the media type of content as `route.At` routes it, on `At`'s +inputs, so a caller takes a media type and a route from one reading of the content. It also moves +`picture.LibreOfficeImage` to gotenberg 9.11.1. + +### Added + +- `route.MediaType(r, size, head, name, mimeType)`, the media type of content as `route.At` routes + it: a `route.Kind`'s type by its signature, such as application/pdf, application/zip for a ZIP or + an ODF package, and application/x-ole-storage for an OLE2 compound file; within a ZIP, an ODF + package, or an OLE2 compound file, the name's extension, by `route.Ext`, first: an OOXML type for + an extension `route.OOXMLExtension` reports, an OpenDocument type for .odt, .ods, .odp, or .odg + and application/zip for .zip within a ZIP or ODF package, and a legacy office type for an + extension `route.LegacyTarget` converts and application/vnd.ms-outlook for .msg within an OLE2 + compound file; and, for content of no signature, text/plain when it routes `route.Text`, + message/rfc822 when it routes `route.Nested`, and application/octet-stream otherwise. It returns + an error only for the reader's own. + +### Changed + +- `picture.LibreOfficeImage` is `gotenberg/gotenberg:9.11.1-libreoffice`, from 9.10.3-libreoffice, + pinned by its multi-arch index digest. + ## [v0.12.0] - 2026-11-29 This release lets `stages.Build` run soffice on the host, so a host without a docker socket has the @@ -721,7 +745,8 @@ fixtures scripts stay in the spike. The [limits page](docs/limits.md) states them: each stage's tool's limits, docproc-ooxml's behavior under a memory bound, the Threader's memory, and the formats no stage reads. -[Unreleased]: https://github.com/standards-lab/docproc/compare/v0.12.0...HEAD +[Unreleased]: https://github.com/standards-lab/docproc/compare/v0.13.0...HEAD +[v0.13.0]: https://github.com/standards-lab/docproc/compare/v0.12.0...v0.13.0 [v0.12.0]: https://github.com/standards-lab/docproc/compare/v0.11.0...v0.12.0 [v0.11.0]: https://github.com/standards-lab/docproc/compare/v0.10.0...v0.11.0 [v0.10.0]: https://github.com/standards-lab/docproc/compare/v0.9.0...v0.10.0 diff --git a/README.md b/README.md index ce9a83dd..cf07483e 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ tags. ## Install ```sh -go get github.com/standards-lab/docproc@v0.12.0 +go get github.com/standards-lab/docproc@v0.13.0 ``` The module's releases are tagged `vX.Y.Z`, and [`CHANGELOG.md`](CHANGELOG.md) states what each diff --git a/cmd/docproc/CHANGELOG.md b/cmd/docproc/CHANGELOG.md index 90706f4b..946053db 100644 --- a/cmd/docproc/CHANGELOG.md +++ b/cmd/docproc/CHANGELOG.md @@ -18,6 +18,9 @@ postgres modules, and each system tool under `tools/` keep their own. stays beside its `export_test.go`. The command line, run directory, and exit codes don't change. - `mise run build` at the repository root writes the docproc command to the git-ignored `bin/docproc`. +- The module requires the docproc base module at v0.12.0, from v0.11.0, whose + [CHANGELOG](../../CHANGELOG.md) states its changes in full. +- The module requires go-core v0.15.0, from v0.14.0; nothing `docproc run` does changes with it. ## [v0.2.9] - 2026-11-28 diff --git a/cmd/docproc/go.mod b/cmd/docproc/go.mod index 3ccb9e5b..765476a8 100644 --- a/cmd/docproc/go.mod +++ b/cmd/docproc/go.mod @@ -3,9 +3,9 @@ module github.com/standards-lab/docproc/cmd/docproc go 1.27.4 require ( - github.com/standards-lab/docproc v0.11.0 + github.com/standards-lab/docproc v0.12.0 github.com/standards-lab/go-cli-sdk v0.4.0 - github.com/standards-lab/go-core v0.14.0 + github.com/standards-lab/go-core v0.15.0 golang.org/x/sys v0.50.0 ) diff --git a/cmd/docproc/go.sum b/cmd/docproc/go.sum index fd2ea069..65bcb04f 100644 --- a/cmd/docproc/go.sum +++ b/cmd/docproc/go.sum @@ -1,9 +1,9 @@ -github.com/standards-lab/docproc v0.11.0 h1:TC1Q+IMZbf2KKkpMuUrjN5Fe5cn2Dftyegh7sCuDlxg= -github.com/standards-lab/docproc v0.11.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= +github.com/standards-lab/docproc v0.12.0 h1:fKof6WCaze3tu+sCI5cx3OgsH5s86Aus65DBsQNA0Mg= +github.com/standards-lab/docproc v0.12.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= github.com/standards-lab/go-cli-sdk v0.4.0 h1:232dyKPD5kqshp0BMEVEZaedwJfvnDVqWLv7m1NQWmI= github.com/standards-lab/go-cli-sdk v0.4.0/go.mod h1:7Y1BCcHtuu8Unxc+Hryjlln+0fbiMYa5xY75aueJ/rY= -github.com/standards-lab/go-core v0.14.0 h1:n8FRpoCqE0HErfo5V1iWASipo3ORx36V6ESQhgFZ27E= -github.com/standards-lab/go-core v0.14.0/go.mod h1:Yl/R+gM9YWczsePBCKXdPGh3FSdZ/5i8SapLIh3BDHU= +github.com/standards-lab/go-core v0.15.0 h1:yYjuUDlI7CupvtHJMT9Db7dAzNug3QJPGAEVruhIJI8= +github.com/standards-lab/go-core v0.15.0/go.mod h1:Yl/R+gM9YWczsePBCKXdPGh3FSdZ/5i8SapLIh3BDHU= golang.org/x/sys v0.50.0 h1:dkKZEFTEKaLr1sjhs0WiKqoi8Jj5nHbS3Njmx1UoMJs= golang.org/x/sys v0.50.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= golang.org/x/text v0.44.0 h1:YItdp/mQNGnsmrgpcdA5yQ3bnRxCfo/Tj/iByGW9GGo= diff --git a/cmd/docproc/internal/app/test/bounds_test.go b/cmd/docproc/internal/app/test/bounds_test.go index 963222f8..17e0639b 100644 --- a/cmd/docproc/internal/app/test/bounds_test.go +++ b/cmd/docproc/internal/app/test/bounds_test.go @@ -55,15 +55,16 @@ var boundVars = []string{ func startingBounds() settings.Run { return settings.Run{ Stages: stages.Options{ - Memory: 2 * gib, - Timeout: 10 * time.Minute, - Idle: 2 * time.Minute, - Inspect: inspect.Options{BombRatio: 1000, BombSize: 1 * gib, Entries: 100_000}, - Concurrency: 1, - Document: document.ImagesRequest{DPI: 150, Text: true, MaxPixels: 64_000_000}, - Video: media.Request{MaxSide: 2048}, - Magick: picture.Limits{Area: 256_000_000, Memory: 1 * gib, Map: 2 * gib, Disk: 8 * gib}, - Audio: audio.Request{Limit: 30 * time.Second}, + Memory: 2 * gib, + LibreOfficeMemory: 2 * gib, + Timeout: 10 * time.Minute, + Idle: 2 * time.Minute, + Inspect: inspect.Options{BombRatio: 1000, BombSize: 1 * gib, Entries: 100_000}, + Concurrency: 1, + Document: document.ImagesRequest{DPI: 150, Text: true, MaxPixels: 64_000_000}, + Video: media.Request{MaxSide: 2048}, + Magick: picture.Limits{Area: 256_000_000, Memory: 1 * gib, Map: 2 * gib, Disk: 8 * gib}, + Audio: audio.Request{Limit: 30 * time.Second}, }, Limits: dispatch.Limits{Parts: 100_000, Bytes: 32 * gib, Depth: 16}, Release: 10 * time.Second, @@ -119,7 +120,10 @@ func TestBounds_EachVariableOverridesItsBound(t *testing.T) { name, value string set func(*settings.Run) }{ - {"DOCPROC_TOOL_MEMORY", "536870912", func(b *settings.Run) { b.Stages.Memory = 512 << 20 }}, + {"DOCPROC_TOOL_MEMORY", "536870912", func(b *settings.Run) { + b.Stages.Memory = 512 << 20 + b.Stages.LibreOfficeMemory = 512 << 20 + }}, {"DOCPROC_UNIT_TIMEOUT", "90s", func(b *settings.Run) { b.Stages.Timeout = 90 * time.Second }}, {"DOCPROC_STREAM_IDLE", "1m30s", func(b *settings.Run) { b.Stages.Idle = 90 * time.Second }}, {"DOCPROC_MAX_PARTS", "50", func(b *settings.Run) { b.Limits.Parts = 50 }}, diff --git a/compose/seaweedfs/Dockerfile b/compose/seaweedfs/Dockerfile index 4a5ffca2..248a79ac 100644 --- a/compose/seaweedfs/Dockerfile +++ b/compose/seaweedfs/Dockerfile @@ -1,6 +1,6 @@ # The harness's SeaweedFS S3 gateway, for the storage module's live tier. # See docs/development.md -FROM chrislusf/seaweedfs:4.55 +FROM chrislusf/seaweedfs:4.56 ENV AWS_ACCESS_KEY_ID=admin \ AWS_SECRET_ACCESS_KEY=secret diff --git a/docs/api.md b/docs/api.md index de5fba87..010bb71a 100644 --- a/docs/api.md +++ b/docs/api.md @@ -95,6 +95,7 @@ type Route string // document, office, vision, vision-converted, nested, onenot func Identify(head []byte) Kind // at most HeadLen (4096) bytes func File(path, name, mimeType string) (Route, string, error) // the route, and why func At(r io.ReaderAt, size int64, head []byte, name, mimeType string) (Route, string, error) +func MediaType(r io.ReaderAt, size int64, head []byte, name, mimeType string) (string, error) func Ext(name string) string // trimmed and lowercased func EncryptedPackage(r io.ReaderAt, size int64) (bool, error) // an OLE2 EncryptedPackage func RARVolume(head []byte) bool // a RAR's main header marks a volume diff --git a/mise.toml b/mise.toml index 252ddb01..8e584c55 100644 --- a/mise.toml +++ b/mise.toml @@ -6,7 +6,7 @@ task.run_auto_install = false [tools] "aqua:google/go-containerregistry" = "0.22.1" -"github:standards-lab/claude-plugins" = { version = "0.25.0", version_prefix = "marathon/v" } +"github:standards-lab/claude-plugins" = { version = "0.26.0", version_prefix = "marathon/v" } "github:ip7z/7zip" = "26.06" actionlint = "1.7.12" go = "1.27.4" diff --git a/picture/spec.go b/picture/spec.go index 46a8daff..9ab354f1 100644 --- a/picture/spec.go +++ b/picture/spec.go @@ -34,8 +34,8 @@ const LibreOfficeMinimum = "24.2" // runs in it under the runner's full lockdown, with no relaxation, so // tool.Image{Ref: LibreOfficeImage} is the whole of it. A caller may run another image, or soffice // on the host through the exec runner. -const LibreOfficeImage = "gotenberg/gotenberg:9.10.3-libreoffice@sha256:" + - "bf3efd63f83fa2ae3f9a8b422aca28984f696a31df94d3159059a1d2c296cc99" +const LibreOfficeImage = "gotenberg/gotenberg:9.11.1-libreoffice@sha256:" + + "e33b622c3bdea412eed6790d4e9cf0c63aa356157703409f9052a6b11ca6e08f" // LibreOfficeSpec declares LibreOffice's soffice, minimum 24.2, for either runner's constructor; // the container runner makes it the entrypoint in place of the image's own. soffice --version diff --git a/postgres/CHANGELOG.md b/postgres/CHANGELOG.md index 19d0d3c6..d39a903a 100644 --- a/postgres/CHANGELOG.md +++ b/postgres/CHANGELOG.md @@ -14,6 +14,8 @@ each system tool under `tools/` keep their own. - The module's unit tests and integration suite sit in its `test/` directory as an external test package. No exported API changes. +- The module requires the docproc base module at v0.12.0, from v0.11.0, and passes its + `dispatchtest.Index` suite; its [CHANGELOG](../CHANGELOG.md) states the base module's changes. ## [v0.1.9] - 2026-11-28 diff --git a/postgres/go.mod b/postgres/go.mod index 69cf56df..21c0a76d 100644 --- a/postgres/go.mod +++ b/postgres/go.mod @@ -4,7 +4,7 @@ go 1.27.4 require ( github.com/jackc/pgx/v5 v5.13.0 - github.com/standards-lab/docproc v0.11.0 + github.com/standards-lab/docproc v0.12.0 github.com/standards-lab/sqlate v0.8.0 github.com/standards-lab/sqlate/postgres v0.9.0 ) diff --git a/postgres/go.sum b/postgres/go.sum index 0d972c87..8444874c 100644 --- a/postgres/go.sum +++ b/postgres/go.sum @@ -13,8 +13,8 @@ github.com/jackc/puddle/v2 v2.2.3 h1:f8HoREISb3l5eO9coPgK7U3hKLhWGokOFVcThl5jrao github.com/jackc/puddle/v2 v2.2.3/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/standards-lab/docproc v0.11.0 h1:TC1Q+IMZbf2KKkpMuUrjN5Fe5cn2Dftyegh7sCuDlxg= -github.com/standards-lab/docproc v0.11.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= +github.com/standards-lab/docproc v0.12.0 h1:fKof6WCaze3tu+sCI5cx3OgsH5s86Aus65DBsQNA0Mg= +github.com/standards-lab/docproc v0.12.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= github.com/standards-lab/sqlate v0.8.0 h1:G1uUIWmc2DxJz5YhtBvIlftfURnb3b2RKsYB59Wa03Y= github.com/standards-lab/sqlate v0.8.0/go.mod h1:pikNmGf/z3x46SBWFXgt/xKIDZuquSgCoXy5OWBFFR4= github.com/standards-lab/sqlate/postgres v0.9.0 h1:l6PXEZ3GQM4+0zekxlSONhyHjpQU8g8StAS16bBqzZE= diff --git a/route/doc.go b/route/doc.go index 4ced76bb..87ac7345 100644 --- a/route/doc.go +++ b/route/doc.go @@ -89,6 +89,11 @@ // [VisionConverted], [Nested], [OneNote], [Archive], [Audio], [Video], [Text], or // [Unrouted]. // - [File] routes the file at a path, and says why; [At] routes content already open. +// - [MediaType] gives the media type of content as At routes it, on At's inputs: a [Kind]'s +// type by its signature; within a ZIP, an ODF package, or an OLE2 compound file, the name's +// extension first, for an OOXML, OpenDocument, or legacy office type, .msg's, or .zip's; and, +// for content of no signature, text/plain, message/rfc822, or application/octet-stream by +// its route. // - [Ext] reads a name's extension; [OOXMLExtension] reports whether it is an OOXML // package's, the one table of them; [LegacyTarget] gives the OOXML format a legacy // extension converts to, the one table of those; [EncryptedPackage] reports whether an OLE2 diff --git a/route/media.go b/route/media.go new file mode 100644 index 00000000..1c6335b2 --- /dev/null +++ b/route/media.go @@ -0,0 +1,130 @@ +package route + +import "io" + +const ( + textPlain = "text/plain" + octetStream = "application/octet-stream" + zipType = "application/zip" +) + +var kindTypes = map[Kind]string{ + PDF: "application/pdf", + PNG: "image/png", + JPEG: "image/jpeg", + GIF: "image/gif", + BMP: "image/bmp", + TIFF: "image/tiff", + EMF: "image/emf", + WMF: "image/wmf", + SVG: "image/svg+xml", + HEIC: "image/heic", + WebP: "image/webp", + AVIF: "image/avif", + ZIP: zipType, + OLE2: "application/x-ole-storage", + ODF: zipType, + RTF: "application/rtf", + WordPerfect: "application/vnd.wordperfect", + PST: "application/vnd.ms-outlook-pst", + OST: "application/vnd.ms-outlook-pst", + Mbox: "application/mbox", + OneStore: "application/onenote", + MSCF: "application/vnd.ms-cab-compressed", + WAV: "audio/wav", + FLAC: "audio/flac", + MP3: "audio/mpeg", + Ogg: "audio/ogg", + M4A: "audio/mp4", + MP4: "video/mp4", + MKV: "video/x-matroska", + WebM: "video/webm", + AVI: "video/x-msvideo", + MPEGPS: "video/mpeg", + OggVideo: "video/ogg", + Gzip: "application/gzip", + Zstd: "application/zstd", + SevenZip: "application/x-7z-compressed", + Tar: "application/x-tar", + RAR4: "application/vnd.rar", + RAR5: "application/vnd.rar", + XZ: "application/x-xz", + Bzip2: "application/x-bzip2", + PE: "application/vnd.microsoft.portable-executable", + ELF: "application/x-executable", + MachO: "application/x-mach-binary", + Shebang: textPlain, + UTF8BOM: textPlain, + UTF16BOM: textPlain, + UTF32BOM: textPlain, +} + +var zipTypes = map[string]string{ + ".zip": zipType, + ".odt": "application/vnd.oasis.opendocument.text", + ".ods": "application/vnd.oasis.opendocument.spreadsheet", + ".odp": "application/vnd.oasis.opendocument.presentation", + ".odg": "application/vnd.oasis.opendocument.graphics", +} + +var legacyTypes = map[string]string{ + "docx": "application/msword", + "xlsx": "application/vnd.ms-excel", + "pptx": "application/vnd.ms-powerpoint", +} + +const outlookType = "application/vnd.ms-outlook" + +// MediaType returns the media type of content r holds, size bytes, whose first bytes are head, +// at most [HeadLen] of them, as [At] routes it, taking At's inputs, so a media type and a route +// come from one reading of the content. Within a ZIP, an ODF package, or an OLE2 compound file, +// name's extension, by [Ext], decides first: an OOXML type for an extension [OOXMLExtension] +// reports; an OpenDocument type for .odt, .ods, .odp, or .odg, and application/zip for .zip, +// within a ZIP or an ODF package; and, within an OLE2 compound file, a legacy office type for an +// extension [LegacyTarget] converts, application/msword, application/vnd.ms-excel, or +// application/vnd.ms-powerpoint, or application/vnd.ms-outlook for .msg. Otherwise the [Kind] +// head's signature names decides, such as application/pdf for a [PDF], application/zip for a ZIP +// or an ODF package, application/x-ole-storage for an OLE2 compound file, application/mbox for an +// mbox, and text/plain for a script or a byte order mark. Content of no signature takes the route +// At gives it, with name and mimeType: text/plain for [Text], message/rfc822 for [Nested], and +// application/octet-stream otherwise. It returns an error only for r's own. +func MediaType(r io.ReaderAt, size int64, head []byte, name, mimeType string) (string, error) { + head = head[:min(len(head), HeadLen)] + kind := Identify(head) + if t := containerType(kind, Ext(name)); t != "" { + return t, nil + } + if t, ok := kindTypes[kind]; ok { + return t, nil + } + routed, _, err := At(r, size, head, name, mimeType) + if err != nil { + return "", err + } + switch routed { + case Text: + return textPlain, nil + case Nested: + return "message/rfc822", nil + } + return octetStream, nil +} + +func containerType(kind Kind, ext string) string { + switch kind { + case ZIP, ODF: + if t, ok := ooxmlTypes[ext]; ok { + return t + } + return zipTypes[ext] + case OLE2: + if t, ok := ooxmlTypes[ext]; ok { + return t + } + if ext == ".msg" { + return outlookType + } + return legacyTypes[LegacyTarget(ext)] + } + return "" +} diff --git a/route/route.go b/route/route.go index 04fc6b5f..8e1ae560 100644 --- a/route/route.go +++ b/route/route.go @@ -90,15 +90,29 @@ const headerLineMax = 64 * 1024 var messageTypes = map[string]bool{"message/rfc822": true, "message/global": true} -var ooxmlExtensions = map[string]bool{ - ".docx": true, ".docm": true, ".dotx": true, ".dotm": true, - ".xlsx": true, ".xlsm": true, ".xltx": true, ".xltm": true, ".xlsb": true, - ".pptx": true, ".pptm": true, ".potx": true, ".potm": true, ".ppsx": true, +var ooxmlTypes = map[string]string{ + ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + ".docm": "application/vnd.ms-word.document.macroEnabled.12", + ".dotx": "application/vnd.openxmlformats-officedocument.wordprocessingml.template", + ".dotm": "application/vnd.ms-word.template.macroEnabled.12", + ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + ".xlsm": "application/vnd.ms-excel.sheet.macroEnabled.12", + ".xltx": "application/vnd.openxmlformats-officedocument.spreadsheetml.template", + ".xltm": "application/vnd.ms-excel.template.macroEnabled.12", + ".xlsb": "application/vnd.ms-excel.sheet.binary.macroEnabled.12", + ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation", + ".pptm": "application/vnd.ms-powerpoint.presentation.macroEnabled.12", + ".potx": "application/vnd.openxmlformats-officedocument.presentationml.template", + ".potm": "application/vnd.ms-powerpoint.template.macroEnabled.12", + ".ppsx": "application/vnd.openxmlformats-officedocument.presentationml.slideshow", } // OOXMLExtension reports whether ext, as [Ext] returns it, is an OOXML package's: one an // encrypted package keeps on its OLE2 compound file. -func OOXMLExtension(ext string) bool { return ooxmlExtensions[ext] } +func OOXMLExtension(ext string) bool { + _, ok := ooxmlTypes[ext] + return ok +} // Ext returns name's extension, its dot included, lowercased, after trailing dots and spaces are // trimmed, as Windows trims them: "Report.PDF. " gives ".pdf". name may be a path, by either @@ -229,7 +243,7 @@ func At(r io.ReaderAt, size int64, head []byte, name, mimeType string) (Route, s kind := Identify(head) switch kind { case OLE2: - if ooxmlExtensions[ext] { + if OOXMLExtension(ext) { encrypted, err := EncryptedPackage(r, size) if err != nil { return "", "", err @@ -345,7 +359,7 @@ func byKind(kind Kind, ext string, head []byte) (Route, string) { switch { case ext == ".xlsb": return Office, "ZIP signature, .xlsb extension, an Excel binary workbook" - case ooxmlExtensions[ext]: + case OOXMLExtension(ext): return Office, "ZIP signature, " + ext + " extension" } return Archive, "ZIP signature without an OOXML extension, " + contentTypesName + ", or ODF mimetype" diff --git a/route/test/media_test.go b/route/test/media_test.go new file mode 100644 index 00000000..e403f160 --- /dev/null +++ b/route/test/media_test.go @@ -0,0 +1,183 @@ +package route_test + +import ( + "errors" + "strings" + "testing" + + "github.com/standards-lab/docproc/route" +) + +func mediaType(t *testing.T, content, name, mimeType string) string { + t.Helper() + head := []byte(content[:min(len(content), route.HeadLen)]) + got, err := route.MediaType(strings.NewReader(content), int64(len(content)), head, name, mimeType) + if err != nil { + t.Fatal(err) + } + return got +} + +func TestMediaTypeKinds(t *testing.T) { + cases := []struct { + name, content, want string + }{ + {"pdf", pdfBytes, "application/pdf"}, + {"png", pngBytes, "image/png"}, + {"jpeg", jpegBytes, "image/jpeg"}, + {"gif", gif89, "image/gif"}, + {"bmp", bmp(40), "image/bmp"}, + {"tiff", tiffLE, "image/tiff"}, + {"emf", emf(1, " EMF"), "image/emf"}, + {"wmf", wmfPlace, "image/wmf"}, + {"svg", svgPlain, "image/svg+xml"}, + {"heic", ftyp("heic", "mif1", "heic"), "image/heic"}, + {"webp", riffForm("WEBP"), "image/webp"}, + {"avif", ftyp("avif", "avif", "mif1", "miaf"), "image/avif"}, + {"zip", zipOf(t, "notes.txt"), "application/zip"}, + {"ole2", ole2Bytes, "application/x-ole-storage"}, + {"odf", odfText, "application/zip"}, + {"rtf", `{\rtf1\ansi`, "application/rtf"}, + {"wordperfect", wordPerfect, "application/vnd.wordperfect"}, + {"pst", pstHeader("SM"), "application/vnd.ms-outlook-pst"}, + {"ost", pstHeader("SO"), "application/vnd.ms-outlook-pst"}, + {"mbox", mboxBytes, "application/mbox"}, + {"onestore", oneSection, "application/onenote"}, + {"cabinet", mscf, "application/vnd.ms-cab-compressed"}, + {"wav", riffForm("WAVE"), "audio/wav"}, + {"flac", "fLaC\x00\x00\x00\x22", "audio/flac"}, + {"mp3", "ID3\x04\x00\x00\x00\x00\x00\x22", "audio/mpeg"}, + {"ogg", oggPage(oggBOS, vorbisPacket), "audio/ogg"}, + {"m4a", ftyp("M4A ", "M4A ", "isom"), "audio/mp4"}, + {"mp4", ftyp("isom", "isom", "iso2", "avc1", "mp41"), "video/mp4"}, + {"matroska", ebml("matroska"), "video/x-matroska"}, + {"webm", ebml("webm"), "video/webm"}, + {"avi", riffForm("AVI "), "video/x-msvideo"}, + {"mpeg program stream", "\x00\x00\x01\xba\x44\x00\x04\x00\x04\x01\x01\x89\xc3\xf8", "video/mpeg"}, + {"ogg video", oggPage(oggBOS, theoraPacket), "video/ogg"}, + {"gzip", "\x1f\x8b\x08\x00", "application/gzip"}, + {"zstd", "\x28\xb5\x2f\xfd\x04", "application/zstd"}, + {"7z", "7z\xbc\xaf\x27\x1c\x00\x04", "application/x-7z-compressed"}, + {"tar", tarHeader("a.txt", "ustar\x0000"), "application/x-tar"}, + {"rar4", rar4(0), "application/vnd.rar"}, + {"rar5", rar5(0x03, 0x01, 0x00, 0x00), "application/vnd.rar"}, + {"xz", "\xfd7zXZ\x00\x00\x04\xe6\xd6\xb4\x46", "application/x-xz"}, + {"bzip2", "BZh91AY&SY\x8a\x1b", "application/x-bzip2"}, + {"pe", peBytes, "application/vnd.microsoft.portable-executable"}, + {"elf", "\x7fELF\x02\x01\x01", "application/x-executable"}, + {"mach-o", "\xfe\xed\xfa\xcf\x00", "application/x-mach-binary"}, + {"shebang", "#!/bin/sh\necho hi\n", "text/plain"}, + {"utf-8 bom", "\xef\xbb\xbfwords", "text/plain"}, + {"utf-16 bom", utf16LE("words"), "text/plain"}, + {"utf-32 bom", "\xff\xfe\x00\x00w\x00\x00\x00", "text/plain"}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + if got := mediaType(t, c.content, "upload.bin", ""); got != c.want { + t.Errorf("MediaType = %q, want %q", got, c.want) + } + }) + } +} + +func TestMediaTypeContainers(t *testing.T) { + ooxml := zipOf(t, "[Content_Types].xml", "word/document.xml") + plain := zipOf(t, "notes.txt") + cases := []struct { + name, content, filename, want string + }{ + {"zip as .docx", plain, "a.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}, + {"zip as .docm", plain, "a.docm", "application/vnd.ms-word.document.macroEnabled.12"}, + {"zip as .dotx", plain, "a.dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template"}, + {"zip as .dotm", plain, "a.dotm", "application/vnd.ms-word.template.macroEnabled.12"}, + {"zip as .XLSX", plain, "A.XLSX", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}, + {"zip as .xlsm", plain, "a.xlsm", "application/vnd.ms-excel.sheet.macroEnabled.12"}, + {"zip as .xltx", plain, "a.xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template"}, + {"zip as .xltm", plain, "a.xltm", "application/vnd.ms-excel.template.macroEnabled.12"}, + {"zip as .xlsb", plain, "a.xlsb", "application/vnd.ms-excel.sheet.binary.macroEnabled.12"}, + {"zip as .pptx", plain, "a.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"}, + {"zip as .pptm", plain, "a.pptm", "application/vnd.ms-powerpoint.presentation.macroEnabled.12"}, + {"zip as .potx", plain, "a.potx", "application/vnd.openxmlformats-officedocument.presentationml.template"}, + {"zip as .potm", plain, "a.potm", "application/vnd.ms-powerpoint.template.macroEnabled.12"}, + {"zip as .ppsx", plain, "a.ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow"}, + {"ooxml package as .zip", ooxml, "a.zip", "application/zip"}, + {"ooxml package unnamed", ooxml, "", "application/zip"}, + {"zip as .odt", plain, "a.odt", "application/vnd.oasis.opendocument.text"}, + + {"odf as .odt", odfText, "a.odt", "application/vnd.oasis.opendocument.text"}, + {"odf as .ods", odfText, "a.ods", "application/vnd.oasis.opendocument.spreadsheet"}, + {"odf as .odp", odfText, "a.odp", "application/vnd.oasis.opendocument.presentation"}, + {"odf as .odg", odfText, "a.odg", "application/vnd.oasis.opendocument.graphics"}, + {"odf as .docx", odfText, "a.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}, + {"odf as .zip", odfText, "a.zip", "application/zip"}, + + {"ole2 as .doc", ole2Bytes, "a.doc", "application/msword"}, + {"ole2 as .dot", ole2Bytes, "a.dot", "application/msword"}, + {"ole2 as .xls", ole2Bytes, "a.xls", "application/vnd.ms-excel"}, + {"ole2 as .xlt", ole2Bytes, "a.xlt", "application/vnd.ms-excel"}, + {"ole2 as .ppt", ole2Bytes, "a.ppt", "application/vnd.ms-powerpoint"}, + {"ole2 as .pps", ole2Bytes, "a.pps", "application/vnd.ms-powerpoint"}, + {"ole2 as .POT", ole2Bytes, "a.POT", "application/vnd.ms-powerpoint"}, + {"ole2 as .msg", ole2Bytes, "a.msg", "application/vnd.ms-outlook"}, + {"ole2 as .docx", ole2Bytes, "a.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}, + {"ole2 as .xlsb", ole2Bytes, "a.xlsb", "application/vnd.ms-excel.sheet.binary.macroEnabled.12"}, + {"ole2 as .zip", ole2Bytes, "a.zip", "application/x-ole-storage"}, + {"ole2 as .odt", ole2Bytes, "a.odt", "application/x-ole-storage"}, + + {"pdf as .doc", pdfBytes, "a.doc", "application/pdf"}, + {"gzip as .zip", "\x1f\x8b\x08\x00", "a.zip", "application/gzip"}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + if got := mediaType(t, c.content, c.filename, ""); got != c.want { + t.Errorf("MediaType = %q, want %q", got, c.want) + } + }) + } +} + +func TestMediaTypeFallBack(t *testing.T) { + const ( + message = "From: ann@example.org\r\nDate: Mon, 12 Jan 2026 10:00:00 +0000\r\n\r\nbody" + shaped = "From: ann@example.org\r\nSubject: x\r\n\r\nbody" + ) + cases := []struct { + name, content, filename, mime, want string + }{ + {"text", "the minutes of the meeting\n", "minutes.txt", "", "text/plain"}, + {"text named .pdf", "the minutes of the meeting\n", "minutes.pdf", "", "text/plain"}, + {"a message by its header", message, "note.txt", "", "message/rfc822"}, + {"a message by its .eml extension", shaped, "a.eml", "", "message/rfc822"}, + {"a message by its stored type", shaped, "fwd", "message/rfc822", "message/rfc822"}, + {"named .eml, not header-shaped", "Dear Bob,\nhello\n", "a.eml", "", "text/plain"}, + {"named .eml, not header-shaped, a nul", "Dear Bob,\x00hello\n", "a.eml", "", "application/octet-stream"}, + {"a nul", "\x00\x01opaque", "sample.bin", "", "application/octet-stream"}, + {"a nul stored as audio", "\x00\x01opaque", "a.mp3", "audio/mpeg", "application/octet-stream"}, + {"text stored as audio", "the minutes\n", "a.mp3", "audio/mpeg", "text/plain"}, + {"empty", "", "", "", "text/plain"}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + if got := mediaType(t, c.content, c.filename, c.mime); got != c.want { + t.Errorf("MediaType = %q, want %q", got, c.want) + } + }) + } +} + +type failingReader struct{ err error } + +func (f failingReader) ReadAt([]byte, int64) (int, error) { return 0, f.err } + +func TestMediaTypeReaderError(t *testing.T) { + failed := errors.New("read failed") + head := []byte("the minutes of the meeting\n") + got, err := route.MediaType(failingReader{failed}, 4096, head, "minutes.txt", "") + if !errors.Is(err, failed) || got != "" { + t.Errorf("MediaType = %q, %v; want the reader's error", got, err) + } + got, err = route.MediaType(failingReader{failed}, 4096, []byte(pdfBytes), "a.pdf", "") + if err != nil || got != "application/pdf" { + t.Errorf("MediaType = %q, %v; want application/pdf without reading past the head", got, err) + } +} diff --git a/storage/CHANGELOG.md b/storage/CHANGELOG.md index a0050025..24cf0611 100644 --- a/storage/CHANGELOG.md +++ b/storage/CHANGELOG.md @@ -14,6 +14,8 @@ each system tool under `tools/` keep their own. - The module's unit tests and integration suite sit in its `test/` directory as an external test package. No exported API changes. +- The module requires the docproc base module at v0.12.0, from v0.11.0, and passes its + `dispatchtest.Content` suite; its [CHANGELOG](../CHANGELOG.md) states the base module's changes. ## [v0.1.9] - 2026-11-28 diff --git a/storage/go.mod b/storage/go.mod index ff13fc73..0527bb46 100644 --- a/storage/go.mod +++ b/storage/go.mod @@ -3,7 +3,7 @@ module github.com/standards-lab/docproc/storage go 1.27.4 require ( - github.com/standards-lab/docproc v0.11.0 + github.com/standards-lab/docproc v0.12.0 github.com/standards-lab/go-storage v0.8.0 github.com/standards-lab/go-storage/s3 v0.3.0 ) diff --git a/storage/go.sum b/storage/go.sum index 469ff375..883c7859 100644 --- a/storage/go.sum +++ b/storage/go.sum @@ -36,8 +36,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.52.0 h1:IaBLmJWiIEtKkjXMgMbYGZk7WKXb github.com/aws/aws-sdk-go-v2/service/sts v1.52.0/go.mod h1:MG6N8U9+lY4LqchrlHPqCOSr7hyxw70XU0Et2YR3eNA= github.com/aws/smithy-go v1.28.9 h1:zkZ058OpNX0iGTK24b+ZUEQSMc11CBA6oO7xtKZfzkY= github.com/aws/smithy-go v1.28.9/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc= -github.com/standards-lab/docproc v0.11.0 h1:TC1Q+IMZbf2KKkpMuUrjN5Fe5cn2Dftyegh7sCuDlxg= -github.com/standards-lab/docproc v0.11.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= +github.com/standards-lab/docproc v0.12.0 h1:fKof6WCaze3tu+sCI5cx3OgsH5s86Aus65DBsQNA0Mg= +github.com/standards-lab/docproc v0.12.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= github.com/standards-lab/go-core v0.12.0 h1:sqrzK6QSppEYpwvVAyiWgzNuOsjfK0Kwe86GPuZpHsU= github.com/standards-lab/go-core v0.12.0/go.mod h1:Yl/R+gM9YWczsePBCKXdPGh3FSdZ/5i8SapLIh3BDHU= github.com/standards-lab/go-storage v0.8.0 h1:r2irs88NfmHRzBBOd9eTYdgS4rqrR6pm/aLaLiL/Gd4= diff --git a/tools/envelope/Cargo.lock b/tools/envelope/Cargo.lock index 6df7dd80..9b68c1ee 100644 --- a/tools/envelope/Cargo.lock +++ b/tools/envelope/Cargo.lock @@ -314,9 +314,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0e5c7d67bc53f435386b2130fdc900488c5703770f6d8a4633060e34288a27" +checksum = "820083d430c52864bf834423fc988cbcf61685d6f9d22a765a64e3f6cfe3521c" dependencies = [ "cfg-if", "cpufeatures", diff --git a/tools/mail/CHANGELOG.md b/tools/mail/CHANGELOG.md index 4ce52ce3..45286fdc 100644 --- a/tools/mail/CHANGELOG.md +++ b/tools/mail/CHANGELOG.md @@ -16,6 +16,9 @@ output contract: a change to them is a change here. This changelog covers docpro - The crate graph locks mail-parser 1.0.3, a patch release, in place of 1.0.2. Its fixes are to ISO-2022-JP text with two escape sequences in a row and to its own HTML-to-text conversion, which docproc-mail doesn't use; the output is unchanged. +- The crate graph locks byteorder 1.5.1 and sha2 0.11.3, patch releases, in place of 1.5.0 and + 0.11.2, the latter yanked; the envelope crate's lock takes sha2 0.11.3 too. The output is + unchanged. ## [v0.2.0] - 2026-11-25 diff --git a/tools/mail/Cargo.lock b/tools/mail/Cargo.lock index bfab9818..f8b54d40 100644 --- a/tools/mail/Cargo.lock +++ b/tools/mail/Cargo.lock @@ -25,9 +25,9 @@ checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db" [[package]] name = "byteorder" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +checksum = "34fb07aac3b9f547c7af8dc897dfe73c10847b6c71130c364bdd7891d979c816" [[package]] name = "cfb" @@ -668,9 +668,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0e5c7d67bc53f435386b2130fdc900488c5703770f6d8a4633060e34288a27" +checksum = "820083d430c52864bf834423fc988cbcf61685d6f9d22a765a64e3f6cfe3521c" dependencies = [ "cfg-if", "cpufeatures", diff --git a/tools/onenote/CHANGELOG.md b/tools/onenote/CHANGELOG.md index 7b8c72d4..ecf693d8 100644 --- a/tools/onenote/CHANGELOG.md +++ b/tools/onenote/CHANGELOG.md @@ -14,6 +14,9 @@ covers docproc-onenote only. - The crate graph locks crc32fast 1.5.6, a patch release, in place of 1.5.5. The output is unchanged. +- The crate graph locks byteorder 1.5.1 and sha2 0.11.3, patch releases, in place of 1.5.0 and + 0.11.2, the latter yanked; the envelope crate's lock takes sha2 0.11.3 too. The output is + unchanged. ## [v0.1.2] - 2026-11-23 diff --git a/tools/onenote/Cargo.lock b/tools/onenote/Cargo.lock index be25dcd2..65a46306 100644 --- a/tools/onenote/Cargo.lock +++ b/tools/onenote/Cargo.lock @@ -40,9 +40,9 @@ checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db" [[package]] name = "byteorder" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +checksum = "34fb07aac3b9f547c7af8dc897dfe73c10847b6c71130c364bdd7891d979c816" [[package]] name = "bytes" @@ -658,9 +658,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0e5c7d67bc53f435386b2130fdc900488c5703770f6d8a4633060e34288a27" +checksum = "820083d430c52864bf834423fc988cbcf61685d6f9d22a765a64e3f6cfe3521c" dependencies = [ "cfg-if", "cpufeatures", diff --git a/tools/ooxml/mise.toml b/tools/ooxml/mise.toml index aac6e159..4771ed1a 100644 --- a/tools/ooxml/mise.toml +++ b/tools/ooxml/mise.toml @@ -3,7 +3,7 @@ [tools] dotnet = "11.0.100" jq = "1.8.2" -uv = "0.13.10" +uv = "0.13.12" [env] DOTNET_CLI_TELEMETRY_OPTOUT = "1"