mronge/MailCore — Issue #8: Stream error in poor network condition cause crashes
Author: rahulvyas
Created: 2012-03-07 09:11:41+00:00
State: open

In poor network conditions if we try to send or download a attachment file for example greator than 1 mb the libetpan cause the app to crash by producing malloc_error_break. Here is the part of code

The stack Trace is like this

- (void)fetchPart {
if (self.fetched == NO) {
struct mailmime_single_fields *mimeFields = NULL;

int encoding = MAILMIME_MECHANISM_8BIT;
mimeFields = mailmime_single_fields_new(mMime->mm_mime_fields, mMime->mm_content_type);
if (mimeFields != NULL && mimeFields->fld_encoding != NULL)
encoding = mimeFields->fld_encoding->enc_type;

char *fetchedData;
size_t fetchedDataLen;
int r;
r = mailmessage_fetch_section(mMessage, mMime, &fetchedData, &fetchedDataLen);
if (r != MAIL_NO_ERROR) {
//The crash appers to be in this part
mailmessage_fetch_result_free(mMessage, fetchedData);
RaiseException(CTMIMEParseError, CTMIMEParseErrorDesc);
}

size_t current_index = 0;
char * result;
size_t result_len;
r = mailmime_part_parse(fetchedData, fetchedDataLen, ¤t_index,
encoding, &result, &result_len);
if (r != MAILIMF_NO_ERROR) {
mailmime_decoded_part_free(result);
RaiseException(CTMIMEParseError, CTMIMEParseErrorDesc);

}
NSData *data = [NSData dataWithBytes:result length:result_len];
mailmessage_fetch_result_free(mMessage, fetchedData);
mailmime_decoded_part_free(result);
mailmime_single_fields_free(mimeFields);
self.data = data;
self.fetched = YES;
}
}

LIBETPAN_EXPORT
int mailmessage_fetch_result_free(mailmessage * msg_info,
char * msg)
{
if (msg_info->msg_driver->msg_fetch_result_free == NULL)
return MAIL_ERROR_NOT_IMPLEMENTED;

msg_info->msg_driver->msg_fetch_result_free(msg_info, msg); //This cause the app to crash. This is the last point in gdb stack trace

return MAIL_NO_ERROR;
}