Bug 9457 - EWS exchange managed API load attachments base64 decoding gives wrong output
Summary: EWS exchange managed API load attachments base64 decoding gives wrong output
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-01-10 11:18 UTC by Ed Avis
Modified: 2013-09-19 13:22 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test program which runs OK on Windows, fails on Mono (6.42 KB, text/plain)
2013-01-10 11:18 UTC, Ed Avis
Details

Description Ed Avis 2013-01-10 11:18:45 UTC
Created attachment 3189 [details]
Test program which runs OK on Windows, fails on Mono

When using Microsoft's Exchange Web Services (EWS) library under Mono, file attachment contents are corrupted, typically by losing a few bytes.  There was an original bug report 762529 in Novell's Bugzilla; I have made a test program which I hope you can use to reproduce the error.

EWS is an XML-based API to fetch message details (including attachments) from a Microsoft Exchange server.  On the wire it uses base64 encoding for the attachment contents.  Somehow, the EWS code running under Mono on Linux performs the base64 decoding wrongly so that the file is corrupted at 8192 byte intervals.  (On Windows with .NET it works fine.)  Yet if you take the base64 encoded string directly from the server's XML response and decode it with the standard FromBase64String method, it gives the correct result.  I don't know what exactly EWS is doing, and it may be that the EWS client library is buggy.  Nonetheless I think this should also be considered a Mono bug because EWS is a commonly used library from Microsoft and it shouldn't do something different (and wrong) under Mono compared to .NET.

Attached is a test program to demonstrate the problem.  You run it passing details of the server to connect to:

- hostname
- domain name for login
- user name for login
- password for login
- name of a folder - e.g. 'Inbox', or a public folder name.  This should contain some messages with attachments.
- max number of messages to fetch

I tested against Exchange Server 2010 and built with version 15.0.0.0 (runtime version v2.0.50727) of Microsoft.Exchange.WebServices.  On Windows I used .NET Framework 4.5.  On Linux I reproduced the bug with both Mono 2.10.5 and 2.10.8.  (The earlier bug report found this behaviour with 2.10.2.)

The program works by first fetching attachment content in the usual way with EWS and then doing it 'by hand' by fishing out the base64 text from the server response and decoding it.  The two should give the same result.  On Windows with .NET the program runs without error but on Mono it will find an attachment where EWS decodes incorrectly.

Please let me know whether you have access to an Exchange Server to reproduce this on or any idea what might be going wrong.  If not, I might have to dig into the EWS client library's code, but I have not done that so far because I don't think the client library is free software.
Comment 1 Ed Avis 2013-01-11 07:23:54 UTC
I also observe this bug with 3.0.3.
Comment 2 Will 2013-09-19 13:20:49 UTC
I'm having an issue with corrupt base64 encoded PNG images being sent from iPads to a web server.  This seems like a likely culprit.
Comment 3 Ed Avis 2013-09-19 13:22:39 UTC
Interesting.  It would be great if you could find a test case that doesn't involve Microsoft Exchange...

Note You need to log in before you can comment on or make changes to this bug.