#4087 closed defect (fixed)
Unable to attach binaries when the SpamFilter is active
Reported by: | Markus Gritsch | Owned by: | Christian Boos |
---|---|---|---|
Priority: | highest | Milestone: | not applicable |
Component: | plugin/spamfilter | Version: | 0.10 |
Severity: | critical | Keywords: | postgresql, binary, unicode |
Cc: | cramm0@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
I wanted to attach a precompiled version of SilverCity to TracSyntaxColoring because SilverCity 0.9.5 is not available for Python 2.4 from SourceForge. The file I tried to upload has the name SilverCity-0.9.5.win32-py2.4.exe
I got the following traceback:
Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/trac/web/main.py", line 381, in dispatch_request dispatcher.dispatch(req) File "/usr/lib/python2.4/site-packages/trac/web/main.py", line 231, in dispatch resp = chosen_handler.process_request(req) File "/usr/lib/python2.4/site-packages/trac/attachment.py", line 361, in process_request self._do_save(req, attachment) File "/usr/lib/python2.4/site-packages/trac/attachment.py", line 474, in _do_save for field, message in manipulator.validate_attachment(req, attachment): File "build/bdist.linux-x86_64/egg/tracspamfilter/adapters.py", line 130, in validate_attachment File "build/bdist.linux-x86_64/egg/tracspamfilter/api.py", line 131, in test File "build/bdist.linux-x86_64/egg/tracspamfilter/model.py", line 119, in insert File "/usr/lib/python2.4/site-packages/trac/db/util.py", line 47, in execute return self.cursor.execute(sql_escape_percent(sql), args) File "/usr/lib/python2.4/site-packages/trac/db/util.py", line 47, in execute return self.cursor.execute(sql_escape_percent(sql), args) ProgrammingError: current transaction is aborted, commands ignored until end of transaction block
Attachments (4)
Change History (30)
comment:1 by , 18 years ago
Component: | wiki → spamfilter |
---|---|
Owner: | changed from | to
Priority: | normal → highest |
Severity: | normal → major |
comment:2 by , 18 years ago
From #4134, it looks like only binary attachments are affected, as the patches were successfully attached there by the same user.
I've looked a bit at the code, but there's nothing obvious… the content extracted from the file was transformed into an unicode string using to_unicode
, so this must always succeed (and there's no unicode error anyway here).
Could it be that PostgreSQL doesn't allow binary content in string fields?
comment:3 by , 18 years ago
That very well might be the case. See http://www.postgresql.org/docs/8.1/interactive/datatype-binary.html
Character strings disallow zero octets, and also disallow any other octet values and sequences of octet values that are invalid according to the database's selected character set encoding.
comment:4 by , 18 years ago
Ok, I see. So either the SpamFilter model should adopt this bytea
binary datatype for the "content" column, or the attachment content should itself be "binary escaped" before being stored in that table.
follow-up: 11 comment:5 by , 18 years ago
Replying to Markus Gritsch:
I wanted to attach a precompiled version of SilverCity to TracSyntaxColoring because SilverCity 0.9.5 is not available for Python 2.4 from SourceForge. The file I tried to upload has the name
SilverCity-0.9.5.win32-py2.4.exe
Is it possible that you put this precompiled file in some other plase, I mean any freeware hosting so we (dummy people ;-) ) could download it?
Best regards Mikolaj
comment:6 by , 18 years ago
PyPI was created for this purpose. You can ask the SilverCity team to either list their package on PyPI, or allow you do to do so.
comment:7 by , 18 years ago
#4211 was marked as duplicate. Apparently, there's a similar issue with pysqlite1 as well.
comment:8 by , 18 years ago
and about the error on #4211, it was not because of a binary, but not sure if this has something to do.
comment:9 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
[4340] changed the attachment filter adapter to ignore binary attachment data (although the comment and author fields are still checked).
follow-up: 12 comment:10 by , 18 years ago
comment:11 by , 18 years ago
Replying to mikolaj:
Is it possible that you put this precompiled file in some other plase, I mean any freeware hosting so we (dummy people ;-) ) could download it?
SilverCity 0.9.7 was released the day before yesterday and it seems that it works also well with Trac. It is available precompiled for Python versions from 2.0 to 2.5.
comment:12 by , 18 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Replying to cboos:
The heuristic
is_binary
used in [4340] is probably not enough:
Happened again today on #4257. Even if the SpamFilter on t.e.o was not actually updated to [4340], I think it's just a matter of time this problem happens again, for the reasons already given above.
comment:13 by , 18 years ago
Severity: | major → critical |
---|
#4440 shows that the problem is beyond binary content. The Unicode content also nearly systematically triggers this exception, which is therefore a very serious.
comment:14 by , 18 years ago
Keywords: | postgresql binary unicode added |
---|---|
Milestone: | → none |
Note that the backtrace is easily reproduced on t.e.o. when pasting the TracUnicode page inside a wiki page (as anonymous, of course).
Traceback (most recent call last): ... File "/usr/lib/python2.4/site-packages/trac/wiki/web_ui.py", line 231, in _do_save for field, message in manipulator.validate_wiki_page(req, page): File "build/bdist.linux-x86_64/egg/tracspamfilter/adapters.py", line 98, in validate_wiki_page File "build/bdist.linux-x86_64/egg/tracspamfilter/api.py", line 131, in test File "build/bdist.linux-x86_64/egg/tracspamfilter/model.py", line 119, in insert File "/usr/lib/python2.4/site-packages/trac/db/util.py", line 50, in execute return self.cursor.execute(sql_escape_percent(sql), args) File "/usr/lib/python2.4/site-packages/trac/db/util.py", line 50, in execute return self.cursor.execute(sql_escape_percent(sql), args) ProgrammingError: current transaction is aborted, commands ignored until end of transaction block
Jonas, it seems that this operation works in other installations (e.g. s0undtech tried to reproduce that but it worked for him). Is there anything special about this table/column on t.e.o, or in the SpamFilter code?
follow-up: 16 comment:15 by , 18 years ago
Summary: | Unable to attach SilverCity-0.9.5.win32-py2.4.exe to Wiki site → Unable to attach binaries when the SpamFilter is active |
---|
#4562 also exhibited the problem.
A simple solution would be to encode the content as base64, for example.
comment:16 by , 18 years ago
comment:18 by , 18 years ago
So actually this is even worse than just a problem with binaries…
It chokes even for "normal" unicode characters in ticket descriptions.
See #4718 for an example.
comment:19 by , 18 years ago
#4858 shows that it's not only this Trac…
There, the error message was:
TypeError: execute() argument 1 must be string without null bytes, not str
comment:20 by , 18 years ago
#4992 is the same - trying to edit unicode page yields error and attaching the file with edited content to the ticket results in the same problem. Seems like this spamfilter tries to analyze every kind of content and chokes on certain character sequences if even .PNG is affected.
comment:21 by , 18 years ago
#5250 marked as duplicate, raising the priority… oops, it's already "highest" priority ;-)
by , 18 years ago
Attachment: | spamfilter_log-base64content-r5329.diff added |
---|
Encode content to base64 before storing it in the db
comment:22 by , 18 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
jonas, can you please try out spamfilter_log-base64content-r5329.diff ?
If this fixes the issues we have on t.e.o, I'll commit it.
comment:23 by , 18 years ago
Cc: | added |
---|
by , 18 years ago
Attachment: | SilverCity-0.9.5.win32-py2.4.exe added |
---|
test binary attachment that originally failed (I'm not logged in)
by , 18 years ago
Attachment: | test4087.txt added |
---|
Make sure the fix works for files that escape the is_binary
test.
comment:24 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Above fix tested on t.e.o and applied in r5390.
by , 17 years ago
Attachment: | SilverCity-0.9.5.win32-py2.4.2.exe added |
---|
check this is working one more time…
comment:25 by , 17 years ago
#5115 was closed as duplicate -
ProgrammingError: invalid byte sequence for encoding "UTF8": 0xe52031
received when retrieving saved content from the db. How that sequence of bytes managed to go in the db without triggering an error at insert time is a bit weird though.
comment:26 by , 10 years ago
Keywords: | postgresql binary unicode → postgresql, binary, unicode |
---|
Yes, this has been noted a couple of time. There's an issue with the latest SpamFilter and attachments in 0.10/0.10-stable.