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

obey accounts_data column length when inserting and searching #29926

Merged
merged 2 commits into from
Nov 26, 2021

Conversation

blizzz
Copy link
Member

@blizzz blizzz commented Nov 26, 2021

This was caught with the following scenario:

  1. In personal account settings write a biography with more than 255 characters
  2. Observe an error message about failed saving
  3. it is saved in oc_accounts
  4. but writing to oc_accounts_data caused a DB exception: `"An exception occurred while executing a query: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column value at row 1"'
  5. This is logged regularly with VerifyUserData background job and spams the log

Solution: since this table is only used for searching phone numbers and additional email currently, it is save to cut off the value that is being written there. To ensure searches work, we prepare the values accordingly. The shortener is taken and adjusted from https://github.com/nextcloud/notifications/blob/67aae02222755d0c7672c634bdfce3859be117b1/lib/Push.php#L485-L491.

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
@blizzz blizzz added bug 3. to review Waiting for reviews feature: profile PRs or issues related to the Profile feature (e.g. Profile page, API, etc.) labels Nov 26, 2021
@blizzz blizzz added this to the Nextcloud 24 milestone Nov 26, 2021
@blizzz blizzz requested review from nickvergessen, PVince81, skjnldsv, Pytal and a team November 26, 2021 15:37
@blizzz
Copy link
Member Author

blizzz commented Nov 26, 2021

/backport to stable23

public static function shortenMultibyteString(string $subject, int $dataLength, int $accuracy = 5): string {
$temp = mb_substr($subject, 0, $dataLength);
// json encodes encapsulates the string in double quotes, they need to be substracted
while ((strlen(json_encode($temp)) - 2) > $dataLength) {
Copy link
Member

Choose a reason for hiding this comment

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

are there scenarios where the while loop never ends ? maybe check if $oldTemp != $temp ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, when you provide $accuracy with <= $dataLength * -1

@nickvergessen
Copy link
Member

Can you leave a comment in notifications to move to the utility function?

Copy link
Member

@Pytal Pytal left a comment

Choose a reason for hiding this comment

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

👌👌

@skjnldsv skjnldsv added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Nov 26, 2021
@skjnldsv
Copy link
Member

Failure unrelated

@blizzz
Copy link
Member Author

blizzz commented Nov 26, 2021

Can you leave a comment in notifications to move to the utility function?

nextcloud/notifications#1121

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 bug feature: profile PRs or issues related to the Profile feature (e.g. Profile page, API, etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants