[Mono-devel-list] mono and .net web services

David Sheldon dave-monolist at earth.li
Tue Jan 20 05:24:07 EST 2004


On Sun, Jan 18, 2004 at 11:43:32AM +0000, David Sheldon wrote:
> Right, I now have a patch that throws the slightly more useful
> System.FormatException. It is attached. Could someone have a look at it
> before I check it in.

Oops, it was attached to the bug, but not the message. Now it is
attached to the message too.

David
-- 
        God gave men brains larger than dogs' so they wouldn't
                hump women's legs at cocktail parties.
                      -- Kate (quoting her mother's book), "Hackers"
-------------- next part --------------
? .FromBase64Transform.cs.swo
? .FromBase64Transform.cs.swp
Index: FromBase64Transform.cs
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System.Security.Cryptography/FromBase64Transform.cs,v
retrieving revision 1.8
diff -u -r1.8 FromBase64Transform.cs
--- FromBase64Transform.cs	20 Jan 2003 03:38:16 -0000	1.8
+++ FromBase64Transform.cs	18 Jan 2004 11:01:51 -0000
@@ -136,6 +136,14 @@
 		}
 
 
+		private byte [] lookupTable; 
+		private byte lookup(byte input) {
+		  byte ret;
+                  if ((input >= lookupTable.Length) || ((ret = lookupTable[input])==-1))
+		    throw new System.FormatException("Invalid character in a Base-64 string.");
+		  return ret;
+		}
+
 		private int DoTransform (byte [] inputBuffer,
 		                         int inputOffset,
 		                         int inputCount,
@@ -154,14 +162,14 @@
 
 			if (inputBuffer[inputCount - 2] == (byte)'=') ++rem;
 
-			byte [] lookup = Base64Table.DecodeTable;
+			lookupTable = Base64Table.DecodeTable;
 			int b0,b1,b2,b3;
 
 			for (int i = 0; i < full; i++) {
-				b0 = lookup [inputBuffer [inputOffset++]];
-				b1 = lookup [inputBuffer [inputOffset++]];
-				b2 = lookup [inputBuffer [inputOffset++]];
-				b3 = lookup [inputBuffer [inputOffset++]];
+				b0 = lookup (inputBuffer [inputOffset++]);
+				b1 = lookup (inputBuffer [inputOffset++]);
+				b2 = lookup (inputBuffer [inputOffset++]);
+				b3 = lookup (inputBuffer [inputOffset++]);
 
 				outputBuffer [outputOffset++] = (byte) ((b0 << 2) | (b1 >> 4));
 				outputBuffer [outputOffset++] = (byte) ((b1 << 4) | (b2 >> 2));
@@ -174,16 +182,16 @@
 			case 0:
 				break;
 			case 1:
-				b0 = lookup [inputBuffer [inputOffset++]];
-				b1 = lookup [inputBuffer [inputOffset++]];
-				b2 = lookup [inputBuffer [inputOffset++]];
+				b0 = lookup (inputBuffer [inputOffset++]);
+				b1 = lookup (inputBuffer [inputOffset++]);
+				b2 = lookup (inputBuffer [inputOffset++]);
 				outputBuffer [outputOffset++] = (byte) ((b0 << 2) | (b1 >> 4));
 				outputBuffer [outputOffset++] = (byte) ((b1 << 4) | (b2 >> 2));
 				res += 2;
 				break;
 			case 2:
-				b0 = lookup [inputBuffer [inputOffset++]];
-				b1 = lookup [inputBuffer [inputOffset++]];
+				b0 = lookup (inputBuffer [inputOffset++]);
+				b1 = lookup (inputBuffer [inputOffset++]);
 				outputBuffer [outputOffset++] = (byte) ((b0 << 2) | (b1 >> 4));
 				++res;
 				break;
@@ -230,7 +238,12 @@
 				Array.Copy (src, srcOff, tmpBuff, accPtr, n);
 				accPtr = count & 3;
 				Array.Copy (src, srcOff + (n - accPtr), accumulator, 0, accPtr);
-				res = DoTransform (tmpBuff, 0, count & (~3), outputBuffer, outputOffset);
+				try {
+					res = DoTransform (tmpBuff, 0, count & (~3), outputBuffer, outputOffset) ;
+				}
+				catch (System.FormatException e) {
+					throw e; 
+				}
 			}
 
 
@@ -267,8 +280,14 @@
 
 			Array.Copy (accumulator, 0, tmpBuf, 0, accPtr);
 			Array.Copy (src, srcOff, tmpBuf, accPtr, n);
-
-			int actLen = DoTransform (tmpBuf, 0, dataLen, res, 0);
+			
+			int actLen;
+			try {
+				actLen = DoTransform (tmpBuf, 0, dataLen, res, 0);
+			}
+			catch (System.FormatException e) {
+				throw e; 
+			}
 
 			accPtr = 0;
 


More information about the Mono-devel-list mailing list