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

Some DAV SEARCH requests use very broad datetime bounds for file search. For example, media searches may use a range such as 0001-01-01 to 4001-01-01 to search across all possible media dates.

On 32-bit PHP, those bounds are outside the timestamp range that can be represented as a native integer:

  • dates before 1970 are below the representable range
  • dates after 2038 are beyond the representable range

When FileSearchBackend::castValue() converts such a datetime with DateTime::getTimestamp(), PHP throws because the resulting timestamp does not fit into a 32-bit integer. PHP 8.2 throws ValueError; PHP 8.3 and newer throw DateRangeError.

transformSearchOperation() then turns the error into:

InvalidArgumentException: Invalid property value for {DAV:}getlastmodified

The whole SEARCH request fails.

Fix

Move DATETIME casting into a small helper and handle datetime values that cannot be represented on the current platform 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 preserves the existing behavior for datetime values that can be represented on the current platform. The added handling only applies when DateTime::getTimestamp() cannot represent the value.

This does not extend the supported date range on 32-bit PHP. It keeps the SEARCH request executable by mapping out-of-range search bounds to the nearest documented 32-bit boundary.

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