Bug 35676 - Encrypting an empty buffer with Security.SecKey.Encrypt throws an IndexOutOfRangeException
Summary: Encrypting an empty buffer with Security.SecKey.Encrypt throws an IndexOutOfR...
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 9.1 (iOS 9.1)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: (C7)
Assignee: Sebastien Pouliot
Depends on:
Reported: 2015-11-09 06:22 UTC by Adam Hartley [MSFT]
Modified: 2016-06-03 11:08 UTC (History)
6 users (show)

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

Sample (29.30 KB, application/zip)
2015-11-09 06:23 UTC, Adam Hartley [MSFT]

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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Adam Hartley [MSFT] 2015-11-09 06:22:20 UTC
## Steps to reproduce

1. Download and run attached sample either on a device or in the simulator
2. Tap "Run Everything"

## Expected result

No exception

## Actual result

From Application Output:

[Runner executing:	Run Everything]
[MonoTouch Version:	9.1.0]
[Assembly:	Xamarin.iOS.dll (64 bits)]
[GC:	sgen+NewRefCount]
[iPhone:	iPhone OS v9.1]
[Device Name:	Adam's iPhone]
[Device UDID:	unknown]
[Device Locale:	en_GB]
[Device Date/Time:	09/11/2015 11:16:12]
[Bundle:	com.your-company.UnitTestApp6]
	[FAIL] CryptoTests.KeyEncryption : System.IndexOutOfRangeException : Array index is out of range.
		at Security.SecKey.Encrypt (SecPadding padding, System.Byte[] plainText, System.Byte[] cipherText) [0x0004a] in /Users/builder/data/lanes/2320/1f068b49/source/maccore/src/Security/Certificate.cs:405 
		at Security.SecKey.Encrypt (SecPadding padding, System.Byte[] plainText, System.Byte[]& cipherText) [0x0000d] in /Users/builder/data/lanes/2320/1f068b49/source/maccore/src/Security/Certificate.cs:415 
		at UnitTestApp6.CryptoTests.KeyEncryption () [0x000fe] in /Users/Adam/Downloads/BugRepro.MonoTouch.SecKey.Encrypt-master/UnitTestApp6/CryptoTests.cs:47 
		at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
		at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00044] in /Users/builder/data/lanes/2320/1f068b49/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:230 
CryptoTests : 70 ms
UnitTestApp6.exe : 72 ms
Tests run: 1 Passed: 0 Inconclusive: 0 Failed: 1 Ignored: 0

## Notes

Possibly a regression as it has been noted that this test has passed for several years.

=== Xamarin Studio ===

Version 5.9.8 (build 0)
Installation UUID: 11a26d86-0d21-407a-8da9-8c197ecc0ad1
	Mono 4.0.5 ((detached/1d8d582)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400050001

=== Apple Developer Tools ===

Xcode 7.1 (9079)
Build 7B91b

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 1f068b4
Branch: master
Build date: 2015-10-27 18:59:21-0400

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/Adam/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 509080000
Git revision: cc5f6e5658589ca7f46210c57fad947e75f30abd
Build date: 2015-10-21 19:27:41-04
Xamarin addins: d77f191bd7d3451adf837b85b38f2b7c60004400

=== Operating System ===

Mac OS X 10.11.1
Darwin Adams-Retina-MacBook-Pro.local 15.0.0 Darwin Kernel Version 15.0.0
    Sat Sep 19 15:53:46 PDT 2015
    root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64
Comment 2 Adam Hartley [MSFT] 2015-11-09 06:23:13 UTC
Created attachment 13730 [details]
Comment 3 Sebastien Pouliot 2015-11-09 10:15:44 UTC
Unlikely to be a regression as the original commit [1] (2010) has the issue.

[1] https://github.com/xamarin/maccore/commit/e1ffee14fa78089296be6f306a5001d4030eaec7#diff-1ad250cb5c49182a39ee43eb60337f9aR307
Comment 4 Sebastien Pouliot 2015-11-09 20:35:55 UTC
Fixed in maccore/master 5c62ed1d94549314ffad781041b16e32bed9a214

QA: additional unit tests added in same commit