Bug#856064: libdbd-mysql-perl: reads of floats currupted as 0

pali at cpan.org pali at cpan.org
Sat Feb 25 00:18:04 UTC 2017


Hi!

On Saturday 25 February 2017 00:41:31 gregor herrmann wrote:
> On Sat, 25 Feb 2017 09:29:23 +1100, Brian May wrote:
> > Package: libdbd-mysql-perl
> > Version: 4.041-1
> > Severity: grave
> > Justification: causes non-serious data loss
> > 
> > When reading floats from mysql, they are always read as 0.
> 
> Thanks for the bug report and all the information!
> 
> > Upstream patch:
> > https://github.com/perl5-dbi/DBD-mysql/pull/102
> 
> This patch doesn't apply against 4.041-1 in Debian (or 4.041
> upstream), and neither against the master branch in the upstream repo
> (so unless I'm missing something, this pull request won't work
> as-is),

That patch in github PR 102 applies cleanly on DBD-mysql master branch. 
It is based on top of master branch. Patch is not merged yet.

Note that nobody was able to create any test which cause this problem 
yet. The only one affected application (which was reported) is amavis. 
Seems unbelievable but it is truth.

> as Pali's master has been massively rewritten since then. [0]

Yes, there are more bug fixes in DBD-mysql. E.g. zerofill support fixed 
in commit dc4d40b1df2f05b9e23105ab6d7b98c77eb318de which worked for 10 
years until 4.040: https://rt.cpan.org/Public/Bug/Display.html?id=118977 
(even it was not explicitly supported).

Or fixed UTF-8 support which was broken for a long time: 
https://github.com/perl5-dbi/DBD-mysql/pull/67

> From looking at the comments in the diff I could possibly find the
> places in the shipped dbdimp.c to make this build somehow, but I'm
> rather reluctant to do this blindly.

Replace "(void) SvNV(sv); SvNOK_only(sv);" by "sv_setnv(sv, SvNV(sv));". 
And similarly also for IV and UV.

> Pali, could you perhaps come up with a patch that applies against
> 4.041?

This one is for libdbd-mysql-perl_4.041-1.dsc:

--- dbdimp.c
+++ dbdimp.c
@@ -4250,8 +4250,7 @@ process:
         switch (mysql_to_perl_type(fields[i].type)) {
         case MYSQL_TYPE_DOUBLE:
           /* Coerce to dobule and set scalar as NV */
-          (void) SvNV(sv);
-          SvNOK_only(sv);
+          sv_setnv(sv, SvNV(sv));
           break;
 
         case MYSQL_TYPE_LONG:
@@ -4259,13 +4258,11 @@ process:
           /* Coerce to integer and set scalar as UV resp. IV */
           if (fields[i].flags & UNSIGNED_FLAG)
           {
-            (void) SvUV(sv);
-            SvIOK_only_UV(sv);
+            sv_setuv(sv, SvUV(sv));
           }
           else
           {
-            (void) SvIV(sv);
-            SvIOK_only(sv);
+            sv_setiv(sv, SvIV(sv));
           }
           break;
 

But if you are fixing "regressions" from older versions, consider apply 
also fix for zerofill.

> 
> Cheers,
> gregor
> 
> [0] especially caea0b774028650c0cbd9d8f9c4a0b47831116df changes the
>     variable types in the switch/case construct



More information about the pkg-perl-maintainers mailing list