lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Diego,

Thank you for your prompt reply. Yes, not only for 512. As far as I can understand it happens when the string exceeds luaL_Buffer size and Lua concatenates the result on the Lua Stack.

I did some debugging and then solved it by moving the opt 2 parameter check prior to encoding/decoding. 

$ diff -u mime.c mime2.c
--- mime.c      2009-11-01 23:56:00.000000000 +0100
+++ mime2.c     2010-03-24 18:49:19.714833000 +0100
@@ -299,9 +299,10 @@
 static int mime_global_unb64(lua_State *L)
 {
     UC atom[4];
-    size_t isize = 0, asize = 0;
+    size_t isize = 0, asize = 0, p2size = 0;
     const UC *input = (UC *) luaL_optlstring(L, 1, NULL, &isize);
     const UC *last = input + isize;
+    const UC *part2 = (UC *) luaL_optlstring(L, 2, NULL, &p2size);
     luaL_Buffer buffer;
     /* end-of-input blackhole */
     if (!input) {
@@ -313,7 +314,7 @@
     luaL_buffinit(L, &buffer);
     while (input < last)
         asize = b64decode(*input++, atom, asize, &buffer);
-    input = (UC *) luaL_optlstring(L, 2, NULL, &isize);
+    input = part2;
     /* if second is nil, we are done */
     if (!input) {
         size_t osize = 0;
@@ -325,6 +326,7 @@
         return 2;
     }
     /* otherwise, process the rest of the input */
+    isize = p2size;
     last = input + isize;
     while (input < last)
         asize = b64decode(*input++, atom, asize, &buffer);
@@ -333,6 +335,7 @@
     return 2;
 }

+
 /*-------------------------------------------------------------------------*\
 * Quoted-printable encoding scheme
 * all (except CRLF in text) can be =XX

Kind Regards,
Martin