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 ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-01-10 11:18 UTC by Ed Avis
Modified: 2013-09-19 13:22 UTC (History)
2 users (show)

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

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 9457 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

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 (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...