Make GetHtmlSource more prone to bad data from libgnomeui
Check all users of GetHtmlSource and make them work as expected
http://bugzilla.gnome.org/show_bug.cgi?id=165629
Index: Tiles/TileFile.cs
===================================================================
RCS file: /cvs/gnome/beagle/Tiles/TileFile.cs,v
retrieving revision 1.22
diff -u -B -p -r1.22 TileFile.cs
--- Tiles/TileFile.cs 17 Mar 2005 14:26:35 -0000 1.22
+++ Tiles/TileFile.cs 18 Mar 2005 23:41:20 -0000
@@ -59,12 +59,13 @@ namespace Beagle.Tile {
Gtk.IconSize size = (Gtk.IconSize) 48;
string path = BU.GnomeIconLookup.LookupMimeIcon (Hit.MimeType,
size);
- if (path != null && path != "") {
- Template["Icon"] = Images.GetHtmlSource (path,
- BU.GnomeIconLookup.GetFileMimeType (path));
- } else {
+ string icon = Images.GetHtmlSource (path,
+ BU.GnomeIconLookup.GetFileMimeType (path));
+
+ if (icon != null)
+ Template["Icon"] = icon;
+ else
Template ["Icon"] = Images.GetHtmlSource ("document", "image/png");
- }
}
[TileAction]
Index: Tiles/TileLauncher.cs
===================================================================
RCS file: /cvs/gnome/beagle/Tiles/TileLauncher.cs,v
retrieving revision 1.5
diff -u -B -p -r1.5 TileLauncher.cs
--- Tiles/TileLauncher.cs 13 Mar 2005 04:37:36 -0000 1.5
+++ Tiles/TileLauncher.cs 18 Mar 2005 23:41:20 -0000
@@ -85,8 +85,12 @@ namespace Beagle.Tile {
protected override void PopulateTemplate ()
{
base.PopulateTemplate ();
+ String icon = Images.GetHtmlSource (ImagePath (), Hit.MimeType);
- Template["Icon"] = Images.GetHtmlSource (ImagePath (), Hit.MimeType);
+ if (icon != null)
+ Template["Icon"] = icon;
+ else
+ Template["Icon"] = Images.GetHtmlSource ("document", "image/png");
}
Index: images/Images.cs
===================================================================
RCS file: /cvs/gnome/beagle/images/Images.cs,v
retrieving revision 1.10
diff -u -B -p -r1.10 Images.cs
--- images/Images.cs 1 Mar 2005 13:47:55 -0000 1.10
+++ images/Images.cs 18 Mar 2005 23:41:20 -0000
@@ -140,7 +140,7 @@ namespace Beagle {
static public string GetHtmlSource (string name,
string mime_type)
{
- if (name == null) {
+ if (name == null || name.Length == 0) {
return null;
} else if (name.StartsWith ("file://")) {
return name;
@@ -156,6 +156,8 @@ namespace Beagle {
// since they'll probably be repeated a lot
stream = GetStream (name);
+ if (stream == null)
+ return null;
byte[] binary_data = new Byte[stream.Length];
long bytes_read = stream.Read(binary_data, 0,