Spamassassin fails to escape backslashes for latest postgres input syntax

Bug #375490 reported by Ian Turner on 2009-05-12
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
spamassassin (Ubuntu)
Undecided
Unassigned

Bug Description

Using:
- Spamassassin
- Postgres
- DBI
- DBD:Pg

I get the following error when attempting to sa-learn --restore:

[24850] dbg: bayes: tok_get: SQL error: ERROR: invalid input syntax for type bytea
[24850] dbg: bayes: _put_token: SQL error: ERROR: invalid input syntax for type bytea
[24850] dbg: bayes: error inserting token for line: t 1 0 1240037056 0178865c33

When run with DBI_TRACE=3, I get the following output:

    -> execute for DBD::Pg::st (DBI::st=HASH(0x99b9c24)~0x99c6f60 '8' '.^M<E4>\<8C>') thr#
814e008
dbdpg: ERROR: invalid input syntax for type bytea

The problem is that Postgres 8.3 is expecting the backslash to be escaped if it represents a literal backslash. The following patch seems to resolve the problem, and I think it is backward-compatible, though not necessarily compatible with SQLite or MySql:

--- spamassassin-3.2.3-0.volatile/lib/Mail/SpamAssassin/BayesStore/SQL.pm 2009-05-12 14:58:28.000000000 +0000
+++ spamassassin-fixed/lib/Mail/SpamAssassin/BayesStore/SQL.pm 2009-05-12 14:07:21.000000
000 +0000
@@ -1522,6 +1522,8 @@
       else {
        # turn unpacked binary token back into binary value
        $token = pack("H*",$token);
+ # Escape backslashes for DB's benefit
+ $token =~ s/\\/\\0134/g;
       }

       unless ($self->_put_token($token, $spam_count, $ham_count, $atime)) {

Kenyon Ralph (kralph) wrote :

Looks like maybe this upstream bug: https://issues.apache.org/SpamAssassin/show_bug.cgi?id=5730

If so, then this should be fixed in spamassassin 3.2.5, which is in hardy-backports (if you're using hardy... although I don't see a spamassassin 3.2.3 published in any current Ubuntu release). Ian, has this been fixed for you?

Changed in spamassassin (Ubuntu):
status: New → Incomplete
Scott Kitterman (kitterman) wrote :

Gutsy was released with 3.2.3-0ubuntu1, but it looks like the reporter was using packages from Debian Volatile:

http://packages.qa.debian.org/s/spamassassin/news/20071101T201215Z.html

Chuck Short (zulcss) wrote :

We'd like to figure out what's causing this bug for you, but we haven't heard back from you in a while. Could you please provide the requested information? Thanks!

Ian Turner (vectro) wrote :

I fixed this issue by applying the patch in Update#0, but if this is fixed in 3.2.5, then this bug can be closed.

Chuck Short (zulcss) wrote :

Closing as per user.

Regards
chuck

Changed in spamassassin (Ubuntu):
status: Incomplete → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.