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

CAST(0x AS BINARY) #16773

Closed
fleming42 opened this issue Mar 28, 2021 · 4 comments
Closed

CAST(0x AS BINARY) #16773

fleming42 opened this issue Mar 28, 2021 · 4 comments
Assignees
Labels
Bug A problem or regression with an existing feature
Projects
Milestone

Comments

@fleming42
Copy link

fleming42 commented Mar 28, 2021

Found a bug where phpmyadmin 5.1.0 constructs an invalid query when selecting "edit" on a row with an empty string in a BLOB or TEXT column. The resultant query has "CAST(0x AS BINARY)" in it, but 0x by itself is invalid. Looks like phpmyadmin expects a nonempty $row to be appended to the '0x' in Util.php.

My fix for this is in Util.php, by changing the function getConditionValue from:

            // do not waste memory building a too big condition
            if (mb_strlen((string) $row) < 1000) {
                // use a CAST if possible, to avoid problems
                // if the field contains wildcard characters % or _

to

            // do not waste memory building a too big condition
            if ((mb_strlen((string) $row) > 0)
                && (mb_strlen((string) $row) < 1000)
            ) {
                // use a CAST if possible, to avoid problems
                // if the field contains wildcard characters % or _

Works for me now, but please examine this and see if this is right. Thanks.

@williamdes
Copy link
Member

Hi @fleming42
Thank you for the nice detailed report, I will have a look
To improve your fix for performance ;)

            $rowLength = mb_strlen((string) $row);
            if (($rowLength > 0) && ($rowLength < 1000)) {

@williamdes
Copy link
Member

Could you confirm @fleming42 that this is the test case you are talking about ?

Sélection_2021040102:02:32001

-- phpMyAdmin SQL Dump
-- version 5.1.1-dev
-- https://www.phpmyadmin.net/
--
-- Hôte : mysql803.williamdes.local:3306
-- Généré le : jeu. 01 avr. 2021 à 00:03
-- Version du serveur : 8.0.3-rc-log
-- Version de PHP : 7.4.14

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";

--
-- Base de données : `public`
--

-- --------------------------------------------------------

--
-- Structure de la table `textx`
--

CREATE TABLE `textx` (
  `tex` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Déchargement des données de la table `textx`
--

INSERT INTO `textx` (`tex`) VALUES
('0'),
('');

--
-- Index pour les tables déchargées
--

--
-- Index pour la table `textx`
--
ALTER TABLE `textx`
  ADD UNIQUE KEY `U` (`tex`(253));
COMMIT;

@williamdes williamdes self-assigned this Apr 1, 2021
@williamdes williamdes added the Bug A problem or regression with an existing feature label Apr 1, 2021
@williamdes williamdes added this to the 5.1.1 milestone Apr 1, 2021
@williamdes williamdes added this to Needs triage in issues via automation Apr 1, 2021
@williamdes williamdes moved this from Needs triage to Reproduced in issues Apr 1, 2021
williamdes added a commit that referenced this issue Apr 1, 2021
Signed-off-by: William Desportes <williamdes@wdes.fr>
@williamdes
Copy link
Member

I made the fix a127061, you can apply it if you want and let me know if it works :)

@fleming42
Copy link
Author

fleming42 commented Apr 1, 2021 via email

issues automation moved this from Reproduced to Closed Apr 2, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A problem or regression with an existing feature
Projects
issues
  
Closed
Development

No branches or pull requests

2 participants