Skip to content

Fix PDO::PARAM_LOB binding for BYTEA columns in CalDAV and CardDAV#1623

Merged
provokateurin merged 2 commits into
sabre-io:masterfrom
sylvinus:master
Mar 10, 2026
Merged

Fix PDO::PARAM_LOB binding for BYTEA columns in CalDAV and CardDAV#1623
provokateurin merged 2 commits into
sabre-io:masterfrom
sylvinus:master

Conversation

@sylvinus

@sylvinus sylvinus commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #1587 and #917

Problem

On PostgreSQL, inserting iCalendar or vCard data containing backslash escape sequences (e.g. \, or \n, which are standard RFC 5545 TEXT escapes) into the calendardata or carddata BYTEA columns fails with:

  SQLSTATE[22P02]: Invalid text representation: 7 ERROR:
  invalid input syntax for type bytea

This happens because PDO binds parameters as PARAM_STR by default. For BYTEA columns, PostgreSQL's text input parser then interprets backslash sequences as invalid octal escapes.

Fix

Bind calendardata/carddata parameters with PDO::PARAM_LOB in all write methods, consistent with the existing fix in Sabre\DAV\PropertyStorage\Backend\PDO::propPatch(). Also switch to named parameters with bindParam() and explicit types for all parameters, matching the PropertyStorage style.

Read methods now handle the is_resource() case since PDO may return BYTEA data as a PHP stream.

Test

Added testCreateCalendarObjectWithIcsEscapes in AbstractPDOTestCase — inserts ICS data with \, and \n escapes, verifies round-trip integrity. Passes on PostgreSQL with the fix, fails without it.

I can also confirm this fixes our own codebase where we had large ICS import break 10% of the time because of such characters in events.

…ckends

When using PostgreSQL, the calendardata and carddata columns are of type
BYTEA. Without explicit PDO::PARAM_LOB binding, PDO sends the data as a
string literal which goes through PostgreSQL's bytea text input parser.
This parser interprets backslash sequences (e.g. \, \n) as octal
escapes, causing "invalid input syntax for type bytea" errors on valid
iCalendar/vCard data containing RFC 5545 TEXT escape sequences.

The PropertyStorage backend (propPatch) already handles this correctly
by using bindParam() with PDO::PARAM_LOB for the value column. This
commit applies the same fix to all write methods in the CalDAV and
CardDAV PDO backends, and adds is_resource()/stream_get_contents()
handling for read methods since PDO returns BYTEA data as streams.

Fixes sabre-io#1587
Fixes sabre-io#917
Comment thread lib/CalDAV/Backend/PDO.php Outdated
@provokateurin provokateurin merged commit d406754 into sabre-io:master Mar 10, 2026
9 checks passed
@codecov

codecov Bot commented Mar 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.26%. Comparing base (0f43b01) to head (cd7f9f8).
⚠️ Report is 23 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1623      +/-   ##
============================================
+ Coverage     97.24%   97.26%   +0.02%     
- Complexity     2836     2844       +8     
============================================
  Files           175      175              
  Lines          8852     8887      +35     
============================================
+ Hits           8608     8644      +36     
+ Misses          244      243       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL error caused by \,

3 participants