Repository navigation
fix(TaskProcessing): detect mimetype from buffer instead of wrapped stream - #66870
Open
MrMegaNova wants to merge 2 commits into
Open
MrMegaNova wants to merge 2 commits into
MrMegaNova wants to merge 2 commits into
Conversation
MrMegaNova
requested review from
icewind1991 and
leftybournes
and removed request for
a team
November 20, 2026 17:28
Author
|
Hi! Gentle ping on this one 🙂 The CI workflows are waiting for maintainer approval, so nothing has run yet. @julien-nc since you looked into #54669 and suggested detecting from the content in #54673, would you mind having a look? This sniffs the first 8 KiB with Assisted by ClaudeCode:claude-opus-5-5 |
…tream The stream returned by File::fopen() is wrapped in a user-space CallbackWrapper when file locking is enabled. mime_content_type() cannot cast such a stream and logs "CallbackWrapper::stream_cast is not implemented!" on every task file download. The handle opened for the detection was also never closed. Read the first bytes instead and sniff them with IMimeTypeDetector::detectString(), then close the handle. Fixes nextcloud#54669 Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Leo <leo.crotet@shellby.io>
getFileContentsInternal() had no test coverage. The new tests serve the file through a CallbackWrapper, as View does when file locking is enabled, so they fail with the previous mime_content_type() call. They check that the type is sniffed from the first 8 KiB, that the node mimetype is kept when detection gives application/octet-stream or the file is empty, and that the handle opened for detection is closed. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Leo <leo.crotet@shellby.io>
MrMegaNova
force-pushed
the
fix/taskprocessing-mime-stream-cast
branch
from
November 30, 2026 13:03
ce2f822 to
ba0f81c
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getFileContentsInternal()callsmime_content_type($node->fopen('rb')). When file locking is enabled (the default),View::basicOperation()wraps the stream inIcewind\Streams\CallbackWrapperto release the shared lock on close.mime_content_type()needs to cast the stream, the user-space wrapper does not implementstream_cast, so every task file download logs:The handle opened for the detection was also never closed, so the shared lock was only released at the end of the request.
This reads the first 8 KiB and sniffs them with
IMimeTypeDetector::detectString()(finfo on a buffer), then closes the handle. The rest is unchanged:getSecureMimeType(), fallback to$node->getMimeType()when the result isapplication/octet-stream. Unlike #54673, the detection is still done on the content, so files without an extension keep their detected type.Testing
On
nextcloud:apache35.0.3 (the function is identical on master), SQLite,testingapp enabled for the fake providers. Tasks scheduled throughPOST /ocs/v2.php/taskprocessing/schedule, files fetched throughGET /ocs/v2.php/taskprocessing/tasks/{id}/file/{fileId}:sample.wavcore:audio2textaudio/wavaudio/wavsample_noext(WAV, no extension)core:audio2textapplication/octet-streamapplication/octet-streamempty.wav(0 bytes)core:audio2textaudio/wavaudio/wavimg_noext(PNG, no extension)core:image2text:ocrimage/pngimage/pngstream_castwarnings innextcloud.log: 4 per run before, 0 after (over 4 runs).php-cs-fixerwithnextcloud/coding-standard: no changes.Unit tests added in
tests/Core/Controller/TaskProcessingApiControllerTest.php: the file is served through aCallbackWrapper, as with file locking enabled. They cover detection from the first bytes, the fallback to the node mimetype (undetected type or empty file) and the closing of the detection handle. They pass with the fix and fail on the previous code.TODO
Checklist
3. to review, feature component)stable32)AI (if applicable)
Claude Code (claude-opus-5-5) helped investigate the issue, write the fix and the unit tests, and draft this description. I reviewed the changes and tested them on a live instance as described above. Each commit carries an
Assisted-bytrailer.