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

PDO_MySQL not properly quoting PDO_PARAM_LOB binary data #15949

Closed
wants to merge 2 commits into from

Conversation

lcobucci
Copy link
Contributor

The prepared statement emulation layer is handling binary content in a way that creates warnings in MySQL.

When analysing the query logs, we saw that the content sent to the server is missing 0x5C characters when the using emulated prepares.

This introduces a minimal test case that reproduces the issue to aid the solution.

More info: doctrine/dbal#6522 (comment)

@lcobucci
Copy link
Contributor Author

@mbeccati as promised 👍

@lcobucci lcobucci force-pushed the add-tests-for-warnings branch 2 times, most recently from 8d3e20d to dd983d9 Compare September 18, 2024 18:41
@mbeccati mbeccati changed the title Reproduce unexpected MySQL warnings for binary values PDO_MySQL not properly quoting PDO_PARAM_LOB binary data Sep 21, 2024
The prepared statement emulation layer is handling binary content in a
way that creates warnings in MySQL.

When analysing the query logs, we saw that the content sent to the
server is missing `0x5C` characters when the using emulated prepares.

This introduces a minimal test case that reproduces the issue to aid the
solution.

More info: doctrine/dbal#6522 (comment)

Signed-off-by: Luís Cobucci <[email protected]>
@mbeccati mbeccati force-pushed the add-tests-for-warnings branch from cb36fc5 to c6710b7 Compare September 21, 2024 06:22
@mbeccati mbeccati changed the base branch from PHP-8.1 to master September 21, 2024 06:23
@mbeccati
Copy link
Contributor

@cmb69 @SakiTakamachi Even though it's a bug fix, I've changed the target to 8.4 as I'm not fully comfortable in making this change across all versions. What do you think?

@cmb69
Copy link
Member

cmb69 commented Sep 21, 2024

[…] as I'm not fully comfortable in making this change across all versions.

In my opinion, this is valid reason to target master only. If nobody complains about the behavioral change in PHP 8.4, but somebody request to backport to an earlier version, we can still consider to do it.

@lcobucci
Copy link
Contributor Author

I agree with the concern and the approach.

The main worry here is having unexpected side-effects with the introduction of the _binary introducer (e.g. apps using PARAM_LOB to bind resources with non-binary data).

There were some PRs that suggested the introduction of a PARAM_BINARY, which could contain the impact of a BC-break.

@SakiTakamachi
Copy link
Member

This is a bug fix of sorts, so I'd vote for it to be merged into 8.4.

@mbeccati
Copy link
Contributor

Since the bug fix mainly affects PDO::quote() I thought it was a good idea to cover that too. The test il passing locally and on most CIs, aside from circleci on arm, with a failure that's baffling me.

========DIFF========
001- string(12) "_binary'%s'"
001+ string(13) "_binary'á\'"
========DONE========
FAIL MySQL PDO->quote(), properly handle binary data [ext/pdo_mysql/tests/pdo_mysql_quote_binary.phpt] 

I've checked and both use the same docker image sha256, so I'd expect the configuration and the quoted string to be the same, but on arm we have one extra byte (a backslash?).

I'll try to add a test on the query result and perhaps use %d for the failing var_dump.

@mbeccati mbeccati force-pushed the add-tests-for-warnings branch from 9b7e2ac to 9fa7ad7 Compare September 24, 2024 19:32
@NattyNarwhal
Copy link
Member

NattyNarwhal commented Sep 24, 2024

FWIW, I do have two PRs about better binary support in PDO I haven’t touched in a while (GH-10343 for PDO_DBLIB specifically, and GH-11674 for a general PARAM_BINARY).

@mbeccati
Copy link
Contributor

@NattyNarwhal Well spotted: #10343 is pretty much the same fix as this, for DBLIB. Perhaps it would be worth combining the tests and making them part of the PDO common suite, so that we can verify that PARAM_LOB properly deals with binary data.

#11462 would be the PR for PARAM_BINARY. I will look have a look in the next few days, but I have a feeliing it is material for discussion for an RFC targeting 8.5.

@NattyNarwhal
Copy link
Member

I wasn't sure if overriding the semantics of PARAM_LOB was right, so that's why I opened the PARAM_BINARY issue and PR.

It's been a while since I've thought of this topic, but I think it's worth discussing in an RFC on the internals mailing list. There's the issues I brought up on those previous threads, but there's likely other ones worth discussing.

@lcobucci
Copy link
Contributor Author

#11462 would be the PR for PARAM_BINARY. I will look have a look in the next few days, but I have a feeliing it is material for discussion for an RFC targeting 8.5.

If we agree that PARAM_LOG should make sure to properly handle binary data when using that emulation layer, I'd say that PARAM_BINARY isn't necessary.

@NattyNarwhal
Copy link
Member

Yeah, though my problem with overriding the semantics of PARAM_LOB was with i.e. CLOB types, which are (large) strings, and thus not binaries, but with LOB semantics. Likewise, a VARBINARY is not a BLOB, and wouldn't fit having LOB semantics. But it seems drivers are a bit mixed on how seriously they take LOBs, so it might not matter anyways.

@lcobucci
Copy link
Contributor Author

Absolutely!

That's what I meant in #15949 (comment) 😄

@mbeccati mbeccati closed this in cba92be Oct 7, 2024
@lcobucci lcobucci deleted the add-tests-for-warnings branch October 7, 2024 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants