Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disallow negative mtime in dav search #10835

Merged
merged 1 commit into from
Aug 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/dav/lib/Files/FileSearchBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ private function castValue(SearchPropertyDefinition $property, $value) {
return 0 + $value;
case SearchPropertyDefinition::DATATYPE_DATETIME:
if (is_numeric($value)) {
return 0 + $value;
return max(0, 0 + $value);
}
$date = \DateTime::createFromFormat(\DateTime::ATOM, $value);
return ($date instanceof \DateTime) ? $date->getTimestamp() : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I currently have the situation that every time I start the Nextcloud iOS App, the error "InvalidArgumentException: Invalid type for field mtime" is written to my Nextcloud log, which seems to be connected to #10835. Because the error is caused by method castValue of class FileSearchBackend: It casts the timestamp "0001-12-30T00:49:56+00:49:56" to boolean false. According to the first user contributed note on this page , this happens for timestamps older than the unix epoch. I have very little PHP experience but I fixed this problem by the following change in line 358 , comments or better workarounds are highly appreciated, thanks in advance!
return ($date instanceof \DateTime && $date->getTimestamp()!= false )? $date->getTimestamp() : 0);
stacktrace_InvalidArgumentException.txt

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cviereck Could we ask you to open this as a new issue so it does not get lost. Thanks for the feedback and debugging.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, feel free to make a PR with the proposed changed.

Expand Down