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

Conversation

icewind1991
Copy link
Member

Prevents potential errors from the database when a client provides an invalid mtime

Signed-off-by: Robin Appelman <robin@icewind.nl>
@icewind1991 icewind1991 added the 3. to review Waiting for reviews label Aug 24, 2018
@icewind1991 icewind1991 added this to the Nextcloud 14 milestone Aug 24, 2018
@MorrisJobke MorrisJobke added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Aug 24, 2018
@MorrisJobke MorrisJobke merged commit 29f215a into master Aug 24, 2018
@MorrisJobke MorrisJobke deleted the dav-search-no-negative-mtime branch August 24, 2018 18:32
@rullzer rullzer mentioned this pull request Aug 24, 2018
3 tasks
@MorrisJobke MorrisJobke mentioned this pull request Aug 24, 2018
@@ -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.

cviereck added a commit to cviereck/server that referenced this pull request Aug 27, 2018
This change solves issues nextcloud#10870, which is caused by method castValue of class FileSearchBackend: It casts the timestamps older than the unix epoch to false., see my comment nextcloud#10835 (comment).
weeman1337 pushed a commit to weeman1337/server that referenced this pull request Sep 6, 2018
This change solves issues nextcloud#10870, which is caused by method castValue of class FileSearchBackend: It casts the timestamps older than the unix epoch to false., see my comment nextcloud#10835 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants