diff options
author | SebastianKrupinski <krupinskis05@gmail.com> | 2024-11-27 22:16:58 -0500 |
---|---|---|
committer | SebastianKrupinski <krupinskis05@gmail.com> | 2024-12-13 20:41:06 -0500 |
commit | 7bf18635450b5fb5e292e02d972e4532f40b96aa (patch) | |
tree | 2670539301d2f1764972f7f7fda89ae2a5beaf7a /apps | |
parent | f3129c4e82582c58cfbd674c64090cdf6d3548fe (diff) | |
download | nextcloud-server-7bf18635450b5fb5e292e02d972e4532f40b96aa.tar.gz nextcloud-server-7bf18635450b5fb5e292e02d972e4532f40b96aa.zip |
fix: replace null character when serializingbackport/49528/stable30
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/lib/DAV/CustomPropertiesBackend.php | 8 | ||||
-rw-r--r-- | apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php | 18 |
2 files changed, 24 insertions, 2 deletions
diff --git a/apps/dav/lib/DAV/CustomPropertiesBackend.php b/apps/dav/lib/DAV/CustomPropertiesBackend.php index dde97cabf37..9485e4fe7f4 100644 --- a/apps/dav/lib/DAV/CustomPropertiesBackend.php +++ b/apps/dav/lib/DAV/CustomPropertiesBackend.php @@ -542,7 +542,9 @@ class CustomPropertiesBackend implements BackendInterface { $value = $value->getHref(); } else { $valueType = self::PROPERTY_TYPE_OBJECT; - $value = serialize($value); + // serialize produces null character + // these can not be properly stored in some databases and need to be replaced + $value = str_replace(chr(0), '\x00', serialize($value)); } return [$value, $valueType]; } @@ -557,7 +559,9 @@ class CustomPropertiesBackend implements BackendInterface { case self::PROPERTY_TYPE_HREF: return new Href($value); case self::PROPERTY_TYPE_OBJECT: - return unserialize($value); + // some databases can not handel null characters, these are custom encoded during serialization + // this custom encoding needs to be first reversed before unserializing + return unserialize(str_replace('\x00', chr(0), $value)); case self::PROPERTY_TYPE_STRING: default: return $value; diff --git a/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php b/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php index 3c527e24363..606632fa45d 100644 --- a/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php +++ b/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -458,4 +459,21 @@ class CustomPropertiesBackendTest extends TestCase { [str_repeat('long_path1', 100), str_repeat('long_path2', 100)] ]; } + + public function testDecodeValueFromDatabaseObjectCurrent(): void { + $propertyValue = 'O:48:"Sabre\CalDAV\Xml\Property\ScheduleCalendarTransp":1:{s:8:"\x00*\x00value";s:6:"opaque";}'; + $propertyType = 3; + $decodeValue = $this->invokePrivate($this->backend, 'decodeValueFromDatabase', [$propertyValue, $propertyType]); + $this->assertInstanceOf(\Sabre\CalDAV\Xml\Property\ScheduleCalendarTransp::class, $decodeValue); + $this->assertEquals('opaque', $decodeValue->getValue()); + } + + public function testDecodeValueFromDatabaseObjectLegacy(): void { + $propertyValue = 'O:48:"Sabre\CalDAV\Xml\Property\ScheduleCalendarTransp":1:{s:8:"' . chr(0) . '*' . chr(0) . 'value";s:6:"opaque";}'; + $propertyType = 3; + $decodeValue = $this->invokePrivate($this->backend, 'decodeValueFromDatabase', [$propertyValue, $propertyType]); + $this->assertInstanceOf(\Sabre\CalDAV\Xml\Property\ScheduleCalendarTransp::class, $decodeValue); + $this->assertEquals('opaque', $decodeValue->getValue()); + } + } |