josephhsieh / mac-dictionary-kit

Automatically exported from code.google.com/p/mac-dictionary-kit
1 stars 0 forks source link

sdconv get SEGV when fetch an zero idx entry #25

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I got some SEGV problem when using sdconv to convert Vietnamese-English 
dictionary.

Here is that idx file:

00000000  00 00 00 00 00 00 00 00  00 27 63 65 6c 6c 69 73  |.........'cellis| 
<----- I don't know why that idx file have null entry like that.
00000010  74 00 00 00 00 00 00 00  00 3d 27 63 68 75 74 69  |t........='chuti|

SEGV signal raised at: 
void convert_with_module(struct convert_module *mod, 
                         gchar *src, GString *dest)
{
    guint32 data_size, sec_size;

    data_size = get_uint32(src); <--- SEGV

And my solution: just detect null entry and skip it.

diff --git a/sdconv/convert.cpp b/sdconv/convert.cpp
index 8fbe30d..845c09d 100644
--- a/sdconv/convert.cpp
+++ b/sdconv/convert.cpp
@@ -156,10 +156,16 @@ void mdk_convert_index_with_module(struct convert_module 
*mod,
                                    GString *dest)
 {
     mdk_entry entry;

     dict->get_entry_by_index(index, &entry);
    gchar *m_str = g_markup_escape_text(entry.key, strlen(entry.key));
+       
+       if  ( (entry.key == NULL) || (strlen(entry.key) == 0) ) {
+               //fprintf(stderr,"entry %d is not valid\n", index + 1);
+               return;
+       }       

    gchar *m_str = g_markup_escape_text(entry.key, strlen(entry.key));       
     g_string_append_printf(dest, "<d:entry id=\"%d\" d:title=\"%s\">\n"
                                  "<d:index d:value=\"%s\"/>\n"
                                  "<h1>%s</h1>\n", 

Original issue reported on code.google.com by hongt...@gmail.com on 28 Aug 2010 at 4:48