diff --git a/pd/src/d_array.c b/pd/src/d_array.c
index 838a2ecb2dd7c9ffb4a4012cccac5efd75e9922b..175704b1d063d15bf97cb1fa1b4d9a1acfef7903 100644
--- a/pd/src/d_array.c
+++ b/pd/src/d_array.c
@@ -298,6 +298,7 @@ static t_int *tabread_tilde_perform(t_int *w)
     int i;
     
     maxindex = x->x_npoints - 1;
+    if (maxindex < 0) goto zero;
     if (!buf) goto zero;
 
     for (i = 0; i < n; i++)
@@ -398,6 +399,7 @@ static t_int *tabread4_tilde_perform(t_int *w)
     int i;
     
     maxindex = x->x_npoints - 3;
+    if (maxindex < 0) goto zero;
 
     if (!buf) goto zero;
 
diff --git a/pd/src/d_soundfile.c b/pd/src/d_soundfile.c
index 285720ea94cdc4d1cef3fca90a3514bbec1ccef5..85d6c573996e036014feea741717fafcb278dcd4 100644
--- a/pd/src/d_soundfile.c
+++ b/pd/src/d_soundfile.c
@@ -29,6 +29,7 @@ objects use Posix-like threads.  */
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <math.h>
 
 #include "m_pd.h"
 
@@ -200,6 +201,21 @@ static void swapstring(char *foo, int doit)
     }
 }
 
+    /* write a sample rate as an 80-bit AIFF-compatible number */
+static void makeaiffsamprate(double sr, unsigned char *shit)
+{
+    int exponent;
+    double mantissa = frexp(sr, &exponent);
+    unsigned long fixmantissa = ldexp(mantissa, 32);
+    shit[0] = (exponent+16382)>>8;
+    shit[1] = exponent+16382;
+    shit[2] = fixmantissa >> 24;
+    shit[3] = fixmantissa >> 16;
+    shit[4] = fixmantissa >> 8;
+    shit[5] = fixmantissa;
+    shit[6] = shit[7] = shit[8] = shit[9] = 0;
+}
+
 /******************** soundfile access routines **********************/
 
 /* This routine opens a file, looks for either a nextstep or "wave" header,
@@ -292,7 +308,8 @@ int open_soundfile_via_fd(int fd, int headersize,
             {
                 long chunksize = swap4(((t_wavechunk *)buf)->wc_size,
                     swap), seekto = headersize + chunksize + 8, seekout;
-                
+                if (seekto & 1)     /* pad up to even number of bytes */
+                    seekto++;
                 if (!strncmp(((t_wavechunk *)buf)->wc_id, "fmt ", 4))
                 {
                     long commblockonset = headersize + 8;
@@ -344,6 +361,8 @@ int open_soundfile_via_fd(int fd, int headersize,
             {
                 long chunksize = swap4(((t_datachunk *)buf)->dc_size,
                     swap), seekto = headersize + chunksize + 8, seekout;
+                if (seekto & 1)     /* pad up to even number of bytes */
+                    seekto++;
                 /* post("chunk %c %c %c %c seek %d",
                     ((t_datachunk *)buf)->dc_id[0],
                     ((t_datachunk *)buf)->dc_id[1],
@@ -374,8 +393,8 @@ int open_soundfile_via_fd(int fd, int headersize,
                         goto badheader;
                 headersize = seekto;
             }
-            bytelimit = swap4(((t_datachunk *)buf)->dc_size, swap);
-            headersize += 8;
+            bytelimit = swap4(((t_datachunk *)buf)->dc_size, swap) - 8;
+            headersize += sizeof(t_datachunk);
         }
     }
         /* seek past header and any sample frames to skip */
@@ -781,8 +800,6 @@ static int create_soundfile(t_canvas *canvas, const char *filename,
     {
         long datasize = nframes * nchannels * bytespersamp;
         long longtmp;
-        static unsigned char dogdoo[] =
-            {0x40, 0x0e, 0xac, 0x44, 0, 0, 0, 0, 0, 0, 'S', 'S', 'N', 'D'};
         if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".aif") &&
             strcmp(filenamebuf + strlen(filenamebuf)-5, ".aiff"))
                 strcat(filenamebuf, ".aif");
@@ -795,10 +812,11 @@ static int create_soundfile(t_canvas *canvas, const char *filename,
         longtmp = swap4(nframes, swap);
         memcpy(&aiffhdr->a_nframeshi, &longtmp, 4);
         aiffhdr->a_bitspersamp = swap2(8 * bytespersamp, swap);
-        memcpy(aiffhdr->a_samprate, dogdoo, sizeof(dogdoo));
-        longtmp = swap4(datasize, swap);
-        memcpy(aiffhdr->a_samprate + sizeof(dogdoo), &longtmp, 4);
-        memset(aiffhdr->a_samprate + sizeof(dogdoo) + 4, 0, 8);
+        makeaiffsamprate(samplerate, aiffhdr->a_samprate);
+        strncpy(((char *)(&aiffhdr->a_samprate))+10, "SSND", 4);
+        longtmp = swap4(datasize + 8, swap);
+        memcpy(((char *)(&aiffhdr->a_samprate))+14, &longtmp, 4);
+        memset(((char *)(&aiffhdr->a_samprate))+18, 0, 8);
         headersize = AIFFPLUS;
     }
     else    /* WAVE format */
@@ -1264,9 +1282,9 @@ static void soundfiler_read(t_soundfiler *x, t_symbol *s,
         
         poswas = lseek(fd, 0, SEEK_CUR);
         eofis = lseek(fd, 0, SEEK_END);
-        if (poswas < 0 || eofis < 0)
+        if (poswas < 0 || eofis < 0 || eofis < poswas)
         {
-            pd_error(x, "lseek failed");
+            pd_error(x, "lseek failed: %ld..%ld", poswas, eofis);
             goto done;
         }
         lseek(fd, poswas, SEEK_SET);
@@ -1283,14 +1301,13 @@ static void soundfiler_read(t_soundfiler *x, t_symbol *s,
         {
             int vecsize;
 
-            garray_resize(garrays[i], finalsize);
+            garray_resize_long(garrays[i], finalsize);
                 /* for sanity's sake let's clear the save-in-patch flag here */
             garray_setsaveit(garrays[i], 0);
-            garray_getfloatwords(garrays[i], &vecsize, 
-                &vecs[i]);
-                /* if the resize failed, garray_resize reported the error */
-            if (vecsize != framesinfile)
+            if (!garray_getfloatwords(garrays[i], &vecsize, &vecs[i])
+                || (vecsize != framesinfile))
             {
+                /* if the resize failed, garray_resize reported the error */
                 pd_error(x, "resize failed");
                 goto done;
             }
@@ -1318,18 +1335,18 @@ static void soundfiler_read(t_soundfiler *x, t_symbol *s,
     for (i = 0; i < argc; i++)
     {
         int vecsize;
-        garray_getfloatwords(garrays[i], &vecsize, &vecs[i]);
-        for (j = itemsread; j < vecsize; j++)
-            vecs[i][j].w_float = 0;
+        if (garray_getfloatwords(garrays[i], &vecsize, &vecs[i]))
+            for (j = itemsread; j < vecsize; j++)
+                vecs[i][j].w_float = 0;
     }
         /* zero out vectors in excess of number of channels */
     for (i = channels; i < argc; i++)
     {
         int vecsize;
         t_word *foo;
-        garray_getfloatwords(garrays[i], &vecsize, &foo);
-        for (j = 0; j < vecsize; j++)
-            foo[j].w_float = 0;
+        if (garray_getfloatwords(garrays[i], &vecsize, &foo))
+            for (j = 0; j < vecsize; j++)
+                foo[j].w_float = 0;
     }
         /* do all graphics updates */
     for (i = 0; i < argc; i++)
@@ -1339,7 +1356,7 @@ static void soundfiler_read(t_soundfiler *x, t_symbol *s,
     goto done;
 usage:
     pd_error(x, "usage: read [flags] filename tablename...");
-    post("flags: -skip <n> -nframes <n> -resize -maxsize <n> ...");
+    post("flags: -skip <n> -resize -maxsize <n> ...");
     post("-raw <headerbytes> <channels> <bytespersamp> <endian (b, l, or n)>.");
 done:
     if (fd >= 0)
@@ -1799,13 +1816,13 @@ static void *readsf_child_main(void *zz)
                 {
                     x->x_fifohead += sysrtn;
                     x->x_bytelimit -= sysrtn;
+                    if (x->x_fifohead == fifosize)
+                        x->x_fifohead = 0;
                     if (x->x_bytelimit <= 0)
                     {
                         x->x_eof = 1;
                         break;
                     }
-                    if (x->x_fifohead == fifosize)
-                        x->x_fifohead = 0;
                 }
 #ifdef DEBUG_SOUNDFILE
                 sprintf(boo, "after: head %d, tail %d\n", 
@@ -2432,20 +2449,23 @@ static t_int *writesf_perform(t_int *w)
         bigendian = x->x_bigendian;
     if (x->x_state == STATE_STREAM)
     {
-        int wantbytes;
+        int wantbytes, roominfifo;
         pthread_mutex_lock(&x->x_mutex);
         wantbytes = sfchannels * vecsize * bytespersample;
-        while (x->x_fifotail > x->x_fifohead &&
-            x->x_fifotail < x->x_fifohead + wantbytes + 1)
+        roominfifo = x->x_fifotail - x->x_fifohead;
+        if (roominfifo <= 0)
+            roominfifo += x->x_fifosize;
+        while (roominfifo < wantbytes + 1)
         {
-#ifdef DEBUG_SOUNDFILE
-            pute("wait...\n");
-#endif
+            fprintf(stderr, "writesf waiting for disk write..\n");
+            fprintf(stderr, "(head %d, tail %d, room %d, want %d)\n",
+                x->x_fifohead, x->x_fifotail, roominfifo, wantbytes);
             sfread_cond_signal(&x->x_requestcondition);
             sfread_cond_wait(&x->x_answercondition, &x->x_mutex);
-#ifdef DEBUG_SOUNDFILE
-            pute("done\n");
-#endif
+            fprintf(stderr, "... done waiting.\n");
+            roominfifo = x->x_fifotail - x->x_fifohead;
+            if (roominfifo <= 0)
+                roominfifo += x->x_fifosize;
         }
 
         soundfile_xferout_sample(sfchannels, x->x_outvec,
@@ -2550,10 +2570,8 @@ static void writesf_open(t_writesf *x, t_symbol *s, int argc, t_atom *argv)
         (x->x_bytespersample * x->x_sfchannels * MAXVECSIZE));
             /* arrange for the "request" condition to be signalled 16
             times per buffer */
-    x->x_sigcountdown = x->x_sigperiod =
-        (x->x_fifosize /
-            (16 * x->x_bytespersample * x->x_sfchannels *
-                x->x_vecsize));
+    x->x_sigcountdown = x->x_sigperiod = (x->x_fifosize /
+            (16 * x->x_bytespersample * x->x_sfchannels * x->x_vecsize));
     sfread_cond_signal(&x->x_requestcondition);
     pthread_mutex_unlock(&x->x_mutex);
 }
@@ -2563,9 +2581,8 @@ static void writesf_dsp(t_writesf *x, t_signal **sp)
     int i, ninlets = x->x_sfchannels;
     pthread_mutex_lock(&x->x_mutex);
     x->x_vecsize = sp[0]->s_n;
-    
     x->x_sigperiod = (x->x_fifosize /
-        (x->x_bytespersample * ninlets * x->x_vecsize));
+            (16 * x->x_bytespersample * x->x_sfchannels * x->x_vecsize));
     for (i = 0; i < ninlets; i++)
         x->x_outvec[i] = sp[i]->s_vec;
     x->x_insamplerate = sp[0]->s_sr;
diff --git a/pd/src/g_array.c b/pd/src/g_array.c
index 91fb0e902de418a0bfb68ac04bc55f77e0941b45..ab50218e6a9a7d228f05272f137c1c390e20338f 100644
--- a/pd/src/g_array.c
+++ b/pd/src/g_array.c
@@ -698,7 +698,7 @@ void garray_arraydialog(t_garray *x, t_symbol *s, int argc, t_atom *argv)
         template_findbyname(x->x_scalar->sc_template),
         gensym("style"), x->x_scalar->sc_vec, 1);*/
 
-        int size;
+        long size;
         t_symbol *argname = sharptodollar(name);
         t_array *a = garray_getarray(x);
         t_template *scalartemplate;
@@ -757,7 +757,7 @@ void garray_arraydialog(t_garray *x, t_symbol *s, int argc, t_atom *argv)
         x->x_style = style;
         if (size != a->a_n)
         {
-            garray_resize(x, size);
+            garray_resize_long(x, size);
         }
         else
         {
@@ -1680,7 +1680,7 @@ static void garray_const(t_garray *x, t_floatarg g)
 }
 
     /* sum of Fourier components; called from routines below */
-static void garray_dofo(t_garray *x, int npoints, t_float dcval,
+static void garray_dofo(t_garray *x, long npoints, t_float dcval,
     int nsin, t_float *vsin, int sineflag)
 {
     double phase, phaseincr, fj;
@@ -1696,7 +1696,7 @@ static void garray_dofo(t_garray *x, int npoints, t_float dcval,
     if (npoints != (1 << ilog2(npoints)))
         post("%s: rounding to %d points", array->a_templatesym->s_name,
             (npoints = (1<<ilog2(npoints))));
-    garray_resize(x, npoints + 3);
+    garray_resize_long(x, npoints + 3);
     phaseincr = 2. * 3.14159 / npoints;
     for (i = 0, phase = -phaseincr; i < array->a_n; i++, phase += phaseincr)
     {
@@ -1716,7 +1716,8 @@ static void garray_dofo(t_garray *x, int npoints, t_float dcval,
 static void garray_sinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv)
 {    
     t_float *svec;
-    int npoints, i;
+    long npoints;
+    int i;
     if (argc < 2)
     {
         error("sinesum: %s: need number of points and partial strengths",
@@ -1739,7 +1740,8 @@ static void garray_sinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv)
 static void garray_cosinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv)
 {
     t_float *svec;
-    int npoints, i;
+    long npoints;
+    int i;
     if (argc < 2)
     {
         error("sinesum: %s: need number of points and partial strengths",
@@ -1956,10 +1958,11 @@ int garray_ambigendian(void)
     return (c==0);
 }
 
-void garray_resize(t_garray *x, t_floatarg f)
+void garray_resize_long(t_garray *x, long n)
 {
     t_array *array = garray_getarray(x);
-    int n = (f < 1 ? 1 : f);
+    if (n < 1)
+        n = 1;
     //fprintf(stderr,"garray_resize %d\n", n);
     array_resize(array, n);
     garray_fittograph(x, n, 1);/*template_getfloat(
@@ -1970,6 +1973,12 @@ void garray_resize(t_garray *x, t_floatarg f)
         canvas_update_dsp();
 }
 
+    /* float version to use as Pd method */
+void garray_resize(t_garray *x, t_floatarg f)
+{
+    garray_resize_long(x, f);
+}
+
 static void garray_print(t_garray *x)
 {
     t_array *array = garray_getarray(x);
diff --git a/pd/src/m_pd.h b/pd/src/m_pd.h
index cf3a09982cd14a484daec87311b95065794c940d..36f19c65e255f728a66c93da6f91c522dddf2e8c 100644
--- a/pd/src/m_pd.h
+++ b/pd/src/m_pd.h
@@ -673,7 +673,8 @@ EXTERN t_float garray_get(t_garray *x, t_symbol *s, t_int indx);
 EXTERN void garray_redraw(t_garray *x);
 EXTERN int garray_npoints(t_garray *x);
 EXTERN char *garray_vec(t_garray *x);
-EXTERN void garray_resize(t_garray *x, t_floatarg f);
+EXTERN void garray_resize(t_garray *x, t_floatarg f);  /* avoid; use this: */
+EXTERN void garray_resize_long(t_garray *x, long n);   /* better version */
 EXTERN void garray_usedindsp(t_garray *x);
 EXTERN void garray_setsaveit(t_garray *x, int saveit);
 EXTERN t_glist *garray_getglist(t_garray *x);