Bug#367235: libvmime0: Crash in libvmime.so.0 when parsing a simple

2006-05-14 Thread Mattias Nordstrom
Hi,

Have you been able to backtrace the segfault?

Running this code:

#include fstream
#include iostream
#include vmime/vmime.hpp

int main()
{

// Read data from f i l e
std::ifstream file;
file.open(hello.eml, std::ios::in | std::ios::binary);
vmime::utility::inputStreamAdapter is(file);
vmime::string data;
vmime::utility::outputStreamStringAdapter os(data);
vmime::utility::bufferedStreamCopy(is, os);

// Actually parse the message
vmime::refvmime::message msg = vmime::createvmime::message();
msg-parse(data);

vmime::refvmime::header hdr = msg-getHeader();
vmime::refvmime::body bdy = msg-getBody();

vmime::charset ch(vmime::charsets::UTF_8);

std::cout  Subject:  
hdr-Subject()-getValue().dynamicCastvmime::text()-getConvertedText(ch)
 std::endl;

}

=== EOF ===

with hello.eml:

Date: Thu, Oct 13 2005 15:22:46 +0200
From: Vincent [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Hello from VMime!


A simple message to test VMime

=== EOF ===

works for me, without a segfault.
Does the above code work for you?

Regards,

-- 
Mattias Nordstrom


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#367235: libvmime0: Crash in libvmime.so.0 when parsing a simple

2006-05-14 Thread Florin Iucha
On Sun, May 14, 2006 at 08:52:37PM +0300, Mattias Nordstrom wrote:
 Have you been able to backtrace the segfault?

Yes I have been able, but it is not interesting ;(

[EMAIL PROTECTED]:~/work/vmime$ ./a.out hello.eml 
Clam Analyze
Subject: Hello from VMime!
Segmentation fault

(gdb) set args hello.eml
(gdb) run
Starting program: /home/florin/work/vmime/a.out hello.eml
Clam Analyze
Subject: Hello from VMime!

Program received signal SIGSEGV, Segmentation fault.
0x2aef79b634da in std::vectorvmime::utility::refvmime::word,
std::allocatorvmime::utility::refvmime::word  ::begin () from
/usr/lib/libvmime.so.0
(gdb) bt
#0  0x2aef79b634da in std::vectorvmime::utility::refvmime::word, 
std::allocatorvmime::utility::refvmime::word  ::begin ()
   from /usr/lib/libvmime.so.0
#1  0x2aef79b61a03 in vmime::text::getWholeBuffer ()
   from /usr/lib/libvmime.so.0
#2  0x0040314b in main ()

 Running this code:

Your code runs fine. Mine crashes, and the difference is... dumping the
second header!

--- vmime.cpp   2006-05-14 13:06:11.0 -0500
+++ vmime_florin.cpp2006-05-14 13:06:05.0 -0500
@@ -25,4 +25,8 @@
 std::cout  Subject:  
 hdr-Subject()-getValue().dynamicCastvmime::text()-getConvertedText(ch)
  std::endl;
+
+std::cout  From:  
+hdr-From()-getValue().dynamicCastvmime::text()-getConvertedText(ch)
+ std::endl;
 }

---cut here---

You can replace hdr-From() with hdr-To(), with no change in the observable
behavior.

florin

-- 
There was a typo, but on the wrong page.
   -- Vipin Kumar


signature.asc
Description: Digital signature


Bug#367235: libvmime0: Crash in libvmime.so.0 when parsing a simple

2006-05-14 Thread Mattias Nordstrom
Florin Iucha wrote:
 Your code runs fine. Mine crashes, and the difference is... dumping the
 second header!

[SNIP]

 You can replace hdr-From() with hdr-To(), with no change in the observable
 behavior.

The problem is probably the fact that From() does not return the same
thing as a Subject(), which is only text.

To extract From, you need to do something like this:

std::cout  From:  
hdr-From()-getValue().dynamicCastvmime::mailbox()-getName().getConvertedText(ch)
   
hdr-From()-getValue().dynamicCastvmime::mailbox()-getEmail()  
 std::endl;

This should fix the segfault. If you take a look at the docs you'll see
that To and Cc also require special treatment, as they contain an array
of addresses.

Regards,

-- 
Mattias Nordstrom


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#367235: libvmime0: Crash in libvmime.so.0 when parsing a simple

2006-05-14 Thread Florin Iucha
On Sun, May 14, 2006 at 09:59:47PM +0300, Mattias Nordstrom wrote:
 Florin Iucha wrote:
  Your code runs fine. Mine crashes, and the difference is... dumping the
  second header!
 
 [SNIP]
 
  You can replace hdr-From() with hdr-To(), with no change in the observable
  behavior.
 
 The problem is probably the fact that From() does not return the same
 thing as a Subject(), which is only text.
 
 To extract From, you need to do something like this:
 
 std::cout  From:  
 hdr-From()-getValue().dynamicCastvmime::mailbox()-getName().getConvertedText(ch)

 hdr-From()-getValue().dynamicCastvmime::mailbox()-getEmail()  
  std::endl;
 
 This should fix the segfault. If you take a look at the docs you'll see
 that To and Cc also require special treatment, as they contain an array
 of addresses.

Oh, I re-read the manual and indeed one has to use vmime::mailbox instead
of vmime::text. You can close this Bug report as operator error.

However...

I did all the voodoo with dynamic cast to vmime::text and stuff, I
expect to get a decent error message back at runtime. Otherwise, what
is the purpose of all the song and dance and all the complicated type
traits and templates?

florin

-- 
There was a typo, but on the wrong page.
   -- Vipin Kumar


signature.asc
Description: Digital signature