Bill GardnerandEdgar 73562bd08c MM-70272: Add aggregate size and depth limits to archive and Slack import extraction (#38009)
* Add aggregate size and depth limits to archive and Slack import extraction

- Add ExtractionBudget to docextractor interface; thread shared byte budget
  and max depth through all extractors so nested archives share one pool
- Cap archive walk at 1000 entries per level and maxArchiveDepth levels
- Cap Slack import at 500MB total decompressed across all ZIP entries

* Add depth-limit and aggregate-size tests

Add TestArchiveExtractorDepthLimit to verify that nested archive
extraction stops at maxDepth levels. Add TestSlackImportTotalSizeLimit
to verify that the aggregate byte cap halts Slack import entry
processing once the limit is reached.

Convert slackImportMaxTotalSize from const to var so tests can lower
the threshold without creating multi-hundred-megabyte fixtures.

* Cap subtext to remaining budget before appending

* Restore Ctx field in ExtractSettings for API compatibility

* Honor caller context cancellation in extractWithTimeout

ExtractSettings.Ctx was restored for API compatibility but was never
observed by extractWithTimeout. A cancelled request context could wait
for the full extraction timeout (or forever when Timeout <= 0).

Now, when Ctx is set, extractWithTimeout runs on a goroutine and selects
on resultCh, timer.C (if Timeout > 0), and ctx.Done() — returning a
cancellation error as soon as the caller context is cancelled. A nil
channel for timer.C means the timeout case simply never fires when
Timeout <= 0. The fast synchronous path is retained for the common case
where neither Ctx nor Timeout is set.

Adds TestExtractContextCancellation covering: already-cancelled context,
mid-extraction cancellation, and ctx vs timeout race (ctx wins first).

* Update pdf.go to use github.com/mattermost/pdf fork

The go.mod was updated upstream to replace github.com/ledongthuc/pdf
with the Mattermost fork github.com/mattermost/pdf. The pdf.go import
was not updated during the rebase because git kept our version of the
file. Also pass context.Background() to GetPlainText, which the fork
extended to take a context.Context.

* Don't log archive entry path in extraction error

Entry paths from user-uploaded archives should not appear in
error messages, per the pattern established in #37987.

* Restore ctx to Extractor interface alongside budget

Adds context.Context back as the first parameter to Extractor.Extract,
alongside the existing ExtractionBudget parameter. This restores
Alejandro's MM-69725 fix: pdfExtractor passes the context down to
GetPlainText(ctx), so when extractWithTimeout returns (timeout or parent
cancellation), the derived context is cancelled and the PDF goroutine
stops at the next page rather than running to completion.

mmPreviewExtractor also gains context propagation via
http.NewRequestWithContext so its outbound HTTP call can be cancelled.
Context-unaware extractors (document, plain) accept and ignore it.

* Fix test extractors to implement updated Extractor interface

* Fix remaining test extractors to implement updated Extractor interface

---------

Co-authored-by: Edgar <edgar.bellotmico@mattermost.com>
2026-09-30 09:16:57 +00:00
2018-05-30 10:23:25 -04:00

Mattermost logo

Mattermost is an open core, self-hosted collaboration platform that offers chat, workflow automation, voice calling, screen sharing, and AI integration. This repo is the primary source for core development on the Mattermost platform; it's written in Go and React, runs as a single Linux binary, and relies on PostgreSQL. A new compiled version is released under an MIT license every month on the 16th.

Deploy Mattermost on-premises, or try it for free in the cloud.

mattermost user interface

Learn more about the following use cases with Mattermost:

Other useful resources:

Table of contents

Install Mattermost

Other install guides:

Native mobile and desktop apps

In addition to the web interface, you can also download Mattermost clients for Android, iOS, Windows PC, macOS, and Linux.

Get Mattermost on Google Play Get Mattermost on the App Store Get Mattermost on Windows PC Get Mattermost on Mac OSX Get Mattermost on Linux

Get security bulletins

Receive notifications of critical security updates. The sophistication of online attackers is perpetually increasing. If you're deploying Mattermost it's highly recommended you subscribe to the Mattermost Security Bulletin mailing list for updates on critical security releases.

Subscribe here

Get involved

Learn more

License

See the LICENSE file for license rights and limitations.

Get the latest news

Contributing

Small Image

Please see CONTRIBUTING.md. Join the Mattermost Contributors server to join community discussions about contributions, development, and more.

S
Description
Mattermost is an open source platform for secure collaboration across the entire software development lifecycle..
Readme AGPL-3.0, Apache-2.0
2.7 GiB
0 Stars 3 Watchers 0 Forks
Languages
TypeScript 48.8%
Go 41.7%
JavaScript 5.1%
SCSS 2.3%
HTML 1.4%
Other 0.5%