Skip to content

CalDAV + PostgreSQL + OC9.1.4, adding events ends with SQL Error #27426

Closed

Description

@momuskk

Steps to reproduce

  1. Connect Calendar via CalDAV to Thunderbird or Outlook (e.g via CalDav Synchronizer)
  2. Add new event with this chars "//\@#", add few attendees (Sometimes just plain text and attendees are enough to cause error)
  3. Check if new event is visible in Calendar via WebBrowser, if not try force synchronization and check again.

Expected behaviour

Event should be visible in browser and all connected devices.

Actual behaviour

There is no event in web browser. When you check PostgreSQL logs you see this error:
"ERROR: invalid input syntax for type bytea".
This problem not exist in 9.0,2. It start happening from time when I upgraded OC to 9.1.4.

Research and temporary solution

I did some research and I found temporary solution and cause of problem. Column "calendardata" in table "oc_schedulingobjects" has type "bytea". Inside Doctrine and OC this type is cast to type "blob".
In type Blob there is no any casting or preparing data to insert (method "convertToDatabaseValue" simply return input data).
In this situation, OC always try put to bytea column data wihich is simple clear string which is incorrect.

My temporary solution is to add manual encoding data to bytea at PHP level (I use only PostgreSQL)
In file "apps/dav/lib/CalDAV/CalDavBackend.php@1267" (method "createSchedulingObject") I changed line:

from: 'calendardata' => $query->createNamedParameter($objectData),
to: 'calendardata' => $query->createNamedParameter(pg_escape_bytea($objectData)),

With this change all Events are adding to database, all my devices are up to date with all events.

I'm attaching ICS file, which can not be added to the database wihtout my temporary solution.
I don't know if this is correct, but:

  • writing/saving events = works OK
  • reading events = works OK (checked in thunderbird, outlook, android 7.0).

Server configuration

Operating system:
openSUSE 13.2
Web server:
nginx 1.10
Database:
PostgreSQL 9.5
PHP version:
5.6 & 7.0
ownCloud version: (see ownCloud admin page)
9.1.4
Updated from an older ownCloud or fresh install:
updated from 9.0.2

Where did you install ownCloud from:
Manual installation from Source Code

Signing status (ownCloud 9.0 and above):
Disabled (I added few icons to "External app")

List of activated apps:
sudo -u wwwrun php occ app:list
Enabled:

  • activity: 2.3.2
  • bookmarks: 0.9.0
  • calendar: 1.4.1
  • comments: 0.3.0
  • configreport: 0.1.1
  • contacts: 1.5.1
  • dav: 0.2.7
  • direct_menu: 0.9.2
  • documents: 0.13.1
  • external: 1.2
  • federatedfilesharing: 0.3.0
  • files: 1.5.1
  • files_antivirus: 0.9.0.0
  • files_pdfviewer: 0.8.1
  • files_sharing: 0.10.0
  • files_texteditor: 2.1
  • files_trashbin: 0.9.0
  • files_versions: 1.3.0
  • files_videoplayer: 0.9.8
  • firstrunwizard: 1.1
  • gallery: 15.0.0
  • notifications: 0.3.0
  • ojsxc: 3.1.1
  • systemtags: 0.3.0
  • tasks: 0.9.4
  • templateeditor: 0.1
  • updatenotification: 0.2.1
  • user_ldap: 0.9.0
    Disabled:
  • announcementcenter
  • encryption
  • federation
  • files_external
  • provisioning_api
  • user_external
    The content of config/config.php:
    sudo -u wwwrun php occ config:list system
    {
    "system": {
    "instanceid": "oc52e41d34a3",
    "passwordsalt": "REMOVED SENSITIVE VALUE",
    "secret": "REMOVED SENSITIVE VALUE",
    "trusted_domains": [
    "cloud.gromar.eu"
    ],
    "datadirectory": "REMOVED SENSITIVE VALUE",
    "overwrite.cli.url": "REMOVED SENSITIVE VALUE",
    "dbtype": "pgsql",
    "version": "9.1.4.2",
    "dbname": "owncloud",
    "dbhost": "REMOVED SENSITIVE VALUE",
    "dbtableprefix": "oc_",
    "dbuser": "REMOVED SENSITIVE VALUE",
    "dbpassword": "REMOVED SENSITIVE VALUE",
    "installed": true,
    "forcessl": true,
    "mail_from_address": "cloud",
    "mail_smtpmode": "php",
    "mail_domain": ""REMOVED SENSITIVE VALUE",
    "preview_libreoffice_path": "/usr/bin/libreoffice",
    "enable_previews": true,
    "enable_avatars": true,
    "appstoreenabled": true,
    "loglevel": 2,
    "maintenance": false,
    "integrity.check.disabled": true,
    "theme": "",
    "filelocking.enabled": "true",
    "memcache.distributed": "\OC\Memcache\Redis",
    "memcache.locking": "\OC\Memcache\Redis",
    "memcache.local": "\OC\Memcache\APCu",
    "redis": {
    "host": "127.0.0.1",
    "port": 6379
    },
    "trashbin_retention_obligation": "auto",
    "ldapIgnoreNamingRules": false,
    "singleuser": false,
    "htaccess.RewriteBase": "/"
    }
    }

Are you using external storage, if yes which one: local/smb/sftp/...
No
Are you using encryption:
No

Client configuration

Browser:
Firefox 54, Thunderbird 45.8
Operating system:
Windows 10 PRO

Logs

Web server error log

Access log

79.188.11.123 - kklimczak [20/Mar/2017:14:50:19 +0100] "PUT /remote.php/caldav/calendars/kklimczak/gromar/7e908a6d-4c4e-48d7-bd62-59ab80fbf1a3.ics HTTP/2.0" 500 3900 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Lightning/4.7.8"

ownCloud log (data/owncloud.log)

{"reqId":"MMq0+O3QvuGpVXVqaAto","remoteAddr":"79.188.11.123","app":"caldav","message":"Exception: {"Message":"An exception occurred while executing 'INSERT INTO \"oc_schedulingobjects\" (\"principaluri\", \"calendardata\", \"uri\", \"lastmodified\", \"etag\", \"size\") VALUES(?, ?, ?, ?, ?, ?)' with params [\"principals\\\/zleszek\", \"BEGIN:VCALENDAR\\r\\nVERSION:2.0\\r\\nPRODID:-\\\/\\\/Sabre\\\/\\\/Sabre VObject 3.5.0\\\/\\\/EN\\r\\nCALSCALE:GREGORIAN\\r\\nMETHOD:REQUEST\\r\\nBEGIN:VTIMEZONE\\r\\nTZID:Europe\\\/Warsaw\\r\\nBEGIN:DAYLIGHT\\r\\nTZOFFSETFROM:+0100\\r\\nTZOFFSETTO:+0200\\r\\nTZNAME:CEST\\r\\nDTSTART:19700329T020000\\r\\nRRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3\\r\\nEND:DAYLIGHT\\r\\nBEGIN:STANDARD\\r\\nTZOFFSETFROM:+0200\\r\\nTZOFFSETTO:+0100\\r\\nTZNAME:CET\\r\\nDTSTART:19701025T030000\\r\\nRRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10\\r\\nEND:STANDARD\\r\\nEND:VTIMEZONE\\r\\nBEGIN:VEVENT\\r\\nCREATED:20170320T131655Z\\r\\nLAST-MODIFIED:20170320T135019Z\\r\\nDTSTAMP:20170320T135019Z\\r\\nUID:7e908a6d-4c4e-48d7-bd62-59ab80fbf1a3\\r\\nSUMMARY:TEST Z pg_escape_bytea\\r\\nORGANIZER;RSVP=TRUE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:[email protected]\\r\\n u\\r\\nATTENDEE;RSVP=TRUE;CN=Zuzanna Leszek;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICI\\r\\n PANT:mailto:[email protected]\\r\\nATTENDEE;RSVP=TRUE;CN=Marcin Pisarski;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTIC\\r\\n IPANT:mailto:[email protected]\\r\\nATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:mailto:klimcz\\r\\n [email protected]\\r\\nATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:mailto:k_klim\\r\\n [email protected]\\r\\nDTSTART;TZID=Europe\\\/Warsaw:20170325T150000\\r\\nDTEND;TZID=Europe\\\/Warsaw:20170325T160000\\r\\nTRANSP:OPAQUE\\r\\nDESCRIPTION:Magiczna tre\\u015b\\u0107 uzyskana za pomoc\\u0105 magicznego proszku.\\\\n\\\\n\\u0119\\r\\n \\u017c\\u017a\\u0107\\u0144\\u0142\\u00f3\\u00d3\\u017b\\u0179\\u0106\\u0141\\u0118\\u20ac\\u015b\\u015b\\u015b\\u015a\\u015a\\\\n \\\\,\\\\,))))))))\\\\;\\\\,\\\\n \\r\\n _))))))))))))))\\\\,\\\\n \\\\\\\\|\\\/ -\\\\\\\\(((((''''((((((((.\\\\n -*-==\\\/\\\/\\\/\\r\\n \\\/\\\/\\\/(('' . ))))))\\\\\\\\,\\\\\\\\n \\\\\\\/|\\\\\\\\\\\\\\\\ ))| o \\\\\\\\;-. '((((( \\\\r\\\\n \\\\\\\\,(\\\\\\\\,\\\\\\\\n ( | \\\/ ) \\\\;))))' \\r\\n \\\\,))^\\\\;(~\\\\n | | | \\\\,))(((( -\\r\\n -----~~~-. %\\\\,\\\\;(\\\\;(>'\\\\;'~\\\\n o)\\\\; \\\\; )))(((~---\\\\r\\\\n ~ :: \\\\\\\\ %%~~)(v\\\\;(('~\\\\\\\\n \\\\\\\\; ''''````\\\\r\\\\n : :::|\\\\\\\\\\\\\\\\\\\\\\\\,__\\\\\\\\,%% )\\\\\\\\;'\\\\; ~\\\\n | _ \\r\\n ) \\\/ :|----' -'\\\\\\\\n ______\\\\\\\/\\\\\\\\\\\\\\\\\\\\\\\/~ | \\\\r\\\\n \\\\\\\/ \\\\\\\/\\\\\\\\n \\\\\\\/~\\\\\\\\;\\\\\\\\;.____\\\\\\\/\\\\\\\\;\\\\\\\\;' \\\\\\\/ ___--\\\\\\\\\\\\r\\\\n ,-( \\\\;\\\\;\\\\;\\\/\\\\n \\\/ \\\/\\\/ \\\\;\\\\;'------~~~~~ \\\/\\\\;\\\\;\\\/\\\\\\\\ \\\/\\\\n \\r\\n \\\/\\\/ | | \\\/ \\\\; \\\\\\\\\\\\;\\\\;\\\\,\\\\\\\\\\\\n (<_ | \\\\; \\r\\n \\\/'\\\\,\\\/-----' >\\\\n \\\\\\\\| ||_ \\r\\n \\\/\\\/\\\\;~~~~~~~~~\\\\n `\\\\\\\\_| (\\\\,~~ -Tua Xiong\\\\n \\r\\n \\\\\\\\\\\\\\\\\\\\n \\r\\n ~~\\\\n\\\\n\\r\\nSEQUENCE:1\\r\\nX-MOZ-GENERATION:1\\r\\nEND:VEVENT\\r\\nEND:VCALENDAR\\r\\n\", \"sabredav-c4ac3dd9-1073-4613-8ad0-d76b0b67074f.ics\", 1490017819, \"32a02e9a5a9429a93c69a36fb9c90c7e\", 2518]:\n\nSQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bytea","Exception":"Doctrine\\DBAL\\Exception\\DriverException","Code":0,"Trace":"#0 \/home\/owncloud\/3rdparty\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/DBALException.php(116): Doctrine\\DBAL\\Driver\\AbstractPostgreSQLDriver->convertException('An exception oc...', Object(Doctrine\\DBAL\\Driver\\PDOException))\n#1 \/home\/owncloud\/3rdparty\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/Connection.php(996): Doctrine\\DBAL\\DBALException::driverExceptionDuringQuery(Object(Doctrine\\DBAL\\Driver\\PDOPgSql\\Driver), Object(Doctrine\\DBAL\\Driver\\PDOException), 'INSERT INTO \"oc...', Array)\n#2 \/home\/owncloud\/lib\/private\/DB\/Connection.php(209): Doctrine\\DBAL\\Connection->executeUpdate('INSERT INTO \"oc...', Array, Array)\n#3 \/home\/owncloud\/3rdparty\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/Query\/QueryBuilder.php(208): OC\\DB\\Connection->executeUpdate('INSERT INTO \"oc...', Array, Array)\n#4 \/home\/owncloud\/lib\/private\/DB\/QueryBuilder\/QueryBuilder.php(141): Doctrine\\DBAL\\Query\\QueryBuilder->execute()\n#5 \/home\/owncloud\/apps\/dav\/lib\/CalDAV\/CalDavBackend.php(1275): OC\\DB\\QueryBuilder\\QueryBuilder->execute()\n#6 \/home\/owncloud\/3rdparty\/sabre\/dav\/lib\/CalDAV\/Schedule\/Inbox.php(104): OCA\\DAV\\CalDAV\\CalDavBackend->createSchedulingObject('principals\/zles...', 'sabredav-c4ac3d...', 'BEGIN:VCALENDAR...')\n#7 \/home\/owncloud\/3rdparty\/sabre\/dav\/lib\/CalDAV\/Schedule\/Plugin.php(460): Sabre\\CalDAV\\Schedule\\Inbox->createFile('sabredav-c4ac3d...', 'BEGIN:VCALENDAR...')\n#8 [internal function]: Sabre\\CalDAV\\Schedule\\Plugin->scheduleLocalDelivery(Object(Sabre\\VObject\\ITip\\Message))\n#9 \/home\/owncloud\/3rdparty\/sabre\/event\/lib\/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\n#10 \/home\/owncloud\/3rdparty\/sabre\/dav\/lib\/CalDAV\/Schedule\/Plugin.php(306): Sabre\\Event\\EventEmitter->emit('schedule', Array)\n#11 \/home\/owncloud\/3rdparty\/sabre\/dav\/lib\/CalDAV\/Schedule\/Plugin.php(528): Sabre\\CalDAV\\Schedule\\Plugin->deliver(Object(Sabre\\VObject\\ITip\\Message))\n#12 \/home\/owncloud\/3rdparty\/sabre\/dav\/lib\/CalDAV\/Schedule\/Plugin.php(294): Sabre\\CalDAV\\Schedule\\Plugin->processICalendarChange(Object(Sabre\\VObject\\Component\\VCalendar), Object(Sabre\\VObject\\Component\\VCalendar), Array, Array, true)\n#13 [internal function]: Sabre\\CalDAV\\Schedule\\Plugin->calendarObjectChange(Object(Sabre\\HTTP\\Request), Object(Sabre\\HTTP\\Response), Object(Sabre\\VObject\\Component\\VCalendar), 'calendars\/kklim...', true, false)\n#14 \/home\/owncloud\/3rdparty\/sabre\/event\/lib\/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\n#15 \/home\/owncloud\/3rdparty\/sabre\/dav\/lib\/CalDAV\/Plugin.php(889): Sabre\\Event\\EventEmitter->emit('calendarObjectC...', Array)\n#16 \/home\/owncloud\/3rdparty\/sabre\/dav\/lib\/CalDAV\/Plugin.php(742): Sabre\\CalDAV\\Plugin->validateICalendar('BEGIN:VCALENDAR...', 'calendars\/kklim...', false, Object(Sabre\\HTTP\\Request), Object(Sabre\\HTTP\\Response), false)\n#17 [internal function]: Sabre\\CalDAV\\Plugin->beforeWriteContent('calendars\/kklim...', Object(OCA\\DAV\\CalDAV\\CalendarObject), 'BEGIN:VCALENDAR...', false)\n#18 \/home\/owncloud\/3rdparty\/sabre\/event\/lib\/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\n#19 \/home\/owncloud\/3rdparty\/sabre\/dav\/lib\/DAV\/Server.php(1068): Sabre\\Event\\EventEmitter->emit('beforeWriteCont...', Array)\n#20 \/home\/owncloud\/3rdparty\/sabre\/dav\/lib\/DAV\/CorePlugin.php(511): Sabre\\DAV\\Server->updateFile('calendars\/kklim...', 'BEGIN:VCALENDAR...', NULL)\n#21 [internal function]: Sabre\\DAV\\CorePlugin->httpPut(Object(Sabre\\HTTP\\Request), Object(Sabre\\HTTP\\Response))\n#22 \/home\/owncloud\/3rdparty\/sabre\/event\/lib\/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\n#23 \/home\/owncloud\/3rdparty\/sabre\/dav\/lib\/DAV\/Server.php(459): Sabre\\Event\\EventEmitter->emit('method:PUT', Array)\n#24 \/home\/owncloud\/3rdparty\/sabre\/dav\/lib\/DAV\/Server.php(248): Sabre\\DAV\\Server->invokeMethod(Object(Sabre\\HTTP\\Request), Object(Sabre\\HTTP\\Response))\n#25 \/home\/owncloud\/apps\/dav\/appinfo\/v1\/caldav.php(83): Sabre\\DAV\\Server->exec()\n#26 \/home\/owncloud\/remote.php(164): require_once('\/home\/owncloud\/...')\n#27 {main}","File":"\/home\/owncloud\/3rdparty\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/Driver\/AbstractPostgreSQLDriver.php","Line":91,"User":"kklimczak"}","level":4,"time":"2017-03-20T13:50:19+00:00","method":"PUT","url":"/remote.php/caldav/calendars/kklimczak/gromar/7e908a6d-4c4e-48d7-bd62-59ab80fbf1a3.ics","user":"kklimczak"}

PostgreSQL log

[owncloud@owncloud 2017-03-20 14:50:19 CET]ERROR: invalid input syntax for type bytea
[owncloud@owncloud 2017-03-20 14:50:19 CET]STATEMENT: INSERT INTO "oc_schedulingobjects" ("principaluri", "calendardata", "uri", "lastmodified", "etag", "size") VALUES($1, $2, $3, $4, $5, $6)

sabredav-c4ac3dd9-1073-4613-8ad0-d76b0b67074f.txt

Activity

  1. added this to the 10.0 milestone on Mar 20, 2017
  2. DeepDiver1975 commented on May 17, 2017

    @DeepDiver1975
    Contributor

    I cannot reproduce this issue - see https://github.com/owncloud/core/pull/27914/files

    from what I can tell this works .... strange

  3. modified the milestones: triage, 10.0 on May 17, 2017
  4. arithmagus commented on Oct 10, 2017

    @arithmagus

    I have the same bug here in "version":"11.0.5.1"
    CalDavBackend.php:1595: 'calendardata' => $query->createNamedParameter($objectData),
    also the Exception
    "Exception: {\"Message\":\"An exception occurred while executing 'INSERT INTO \\\"oc_schedulingobjects\\\"
    and the error message
    Invalid text representation: 7 FEHLER: ung\\u00fcltige Eingabesyntax f\\u00fcr Typ bytea\"

    The problem seems to occur when an newline is added to the calenderdata between two attendees.
    The first attendee is no problem, adding a second attendee results in this error 500.
    The caldav client is Thunderbird Lightning 52.3.0.

    Also fixed by adding "pg_escape_bytea" in line 1595. Thanks momuskk for this hint.

  5. ownclouders commented on Dec 21, 2017

    @ownclouders
    Contributor

    Hey, this issue has been closed because the label status/STALE is set and there were no updates for 7 days. Feel free to reopen this issue if you deem it appropriate.

    (This is an automated comment from GitMate.io.

  6. DeepDiver1975 commented on Feb 21, 2018

    @DeepDiver1975
    Contributor

    Finally reproduced! - Fix is in #27914

  7. DeepDiver1975 commented on Feb 28, 2018

    @DeepDiver1975
    Contributor

    fixed.

  8. lock commented on Jul 31, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  9. locked as resolved and limited conversation to collaborators on Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions