gwui.py:260:render:TypeError: WebKitWebView.load_html_string() argument 1 must be string without null bytes, not str

Bug #647049 reported by Tom "spot" Callaway
22
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Gwibber
Fix Released
Undecided
Unassigned

Bug Description

Fedora has gotten a few bugs filed with the below traceback:

gwui.py:260:render:TypeError: WebKitWebView.load_html_string() argument 1 must be string without null bytes, not str

Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/gwibber/gwui.py", line 376, in on_stream_change
    self.update()
  File "/usr/lib/python2.6/site-packages/gwibber/gwui.py", line 391, in update
    self.messages.update(self.navigation.selected_stream)
  File "/usr/lib/python2.6/site-packages/gwibber/gwui.py", line 723, in update
    self.messages = self.message_view.render([selected_stream], count)
  File "/usr/lib/python2.6/site-packages/gwibber/gwui.py", line 781, in render
    accounts=accounts)
  File "/usr/lib/python2.6/site-packages/gwibber/gwui.py", line 260, in render
    self.load_html_string(content, "file://%s/" % os.path.dirname(template_path))
TypeError: WebKitWebView.load_html_string() argument 1 must be string without null bytes, not str

Thanks to the help of Toshio Kuratomi, I was able to narrow this down to a simple test case:

"""CODE STARTS"""
import os, webkit
template_path = '/usr/share/gwibber/ui/themes/default/template.mako'
content = 'foo \x00'

web = webkit.WebView()
web.load_html_string(content, "file://%s/" % os.path.dirname(template_path))
"""CODE ENDS"""

Somehow, in certain situations, \x00 ends up in the content string, and load_html_string chokes on it. Since content contains all of the processed messages which are trying to be displayed (but is used after this load_html_string() call), the safest bet seemed to be to simply replace it with a " " whenever it is found in content. This resolves the test case, and would seem to resolve the gwibber crashes as well. I've attached a patch which should stop these crashes from occurring.

Tags: patch
Revision history for this message
Tom "spot" Callaway (tcallawa) wrote :
Revision history for this message
Tom "spot" Callaway (tcallawa) wrote :
Revision history for this message
David Klasinc (bigwhale) wrote :

This still exist in current trunk and I was hit by it today. Proposed patch will fix the error. I modified it a little bit and also added some code that will prevent \x00 characters being in the database in the first place.

David Klasinc (bigwhale)
Changed in gwibber:
status: New → Confirmed
Victor Vargas (kamus)
tags: added: patch
Revision history for this message
Victor Vargas (kamus) wrote :

Ken, would you mind to review and check this patch please :)

Revision history for this message
ahmadzxc (ahmad-almomani5) wrote :

thanks all
but i don’t know how to apply these patches any help please !!!!

Revision history for this message
Ken VanDine (ken-vandine) wrote :

The handling of the null bytes was fixed in the service at some point in the 3.2 series.

Changed in gwibber:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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