Skip to content

fix(dav): handle out-of-range datetime values in file search#60364

Open
Ahnz wants to merge 1 commit into
nextcloud:masterfrom
Ahnz:fix/dav-search-datetime-out-of-range
Open

fix(dav): handle out-of-range datetime values in file search#60364
Ahnz wants to merge 1 commit into
nextcloud:masterfrom
Ahnz:fix/dav-search-datetime-out-of-range

Conversation

@Ahnz
Copy link
Copy Markdown

@Ahnz Ahnz commented May 13, 2026

Summary

On 32-bit PHP, DateTime::getTimestamp() throws ValueError on PHP 8.2 or DateRangeError on PHP 8.3+ when the datetime cannot be represented as a native integer.

WebDAV SEARCH requests can use broad datetime ranges for file search, for example media searches with dates before 1970 or after 2038. In that case FileSearchBackend::castValue() currently throws and transformSearchOperation() turns the error into:

InvalidArgumentException: Invalid property value for {DAV:}getlastmodified

The whole SEARCH request then fails.

Fix

Move DATETIME casting into a small helper and handle out-of-range timestamps by clamping them to the platform-supported range:

  • values below the representable range to 0
  • values beyond the platform max to PHP_INT_MAX

This keeps the SEARCH request executable and matches the documented 32-bit date limitations.

Notes

The fix is generic for DAV datetime search values and is not specific to the iOS client.

Related issues:

Testing

  • Tested manually on 32-bit PHP with Nextcloud Server 33.0.3.2
  • Tested with Nextcloud iOS 33.0.8
  • Verified that the Photos/Media tab loads again
  • Verified that Invalid property value for {DAV:}getlastmodified no longer appears in nextcloud.log
  • Ran php -l apps/dav/lib/Files/FileSearchBackend.php

Checklist

AI

  • The content of this PR was partly or fully generated using AI.

On 32-bit PHP, DateTime::getTimestamp() can throw ValueError
or DateRangeError when a WebDAV SEARCH datetime value is outside
the platform's representable integer timestamp range.

This can happen when clients send broad date ranges for file search,
for example dates before 1970 or after 2038. The exception is currently
converted to an InvalidArgumentException and aborts the whole SEARCH
request.

Clamp unrepresentable datetime values to the nearest platform boundary
instead, so the SEARCH request can still be executed.

Signed-off-by: Iven Ahrens <25607353+Ahnz@users.noreply.github.com>
@Ahnz Ahnz requested a review from a team as a code owner May 13, 2026 19:57
@Ahnz Ahnz requested review from ArtificialOwl, CarlSchwan, artonge and salmart-dev and removed request for a team May 13, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant