diff -urNad gnupg-1.4.2~/mpi/mpicoder.c gnupg-1.4.2/mpi/mpicoder.c --- gnupg-1.4.2~/mpi/mpicoder.c 2005-05-31 06:30:05.000000000 +0000 +++ gnupg-1.4.2/mpi/mpicoder.c 2005-09-29 00:52:19.000000000 +0000 @@ -80,16 +80,20 @@ mpi_limb_t a; MPI val = MPI_NULL; + if (nread == nmax) + goto overflow; if( (c = iobuf_get(inp)) == -1 ) goto leave; - if (++nread >= nmax) - goto overflow; + nread++; nbits = c << 8; + + if (nread == nmax) + goto overflow; if( (c = iobuf_get(inp)) == -1 ) goto leave; - if (++nread >= nmax) - goto overflow; + nread++; nbits |= c; + if( nbits > MAX_EXTERN_MPI_BITS ) { log_error("mpi too large for this implementation (%u bits)\n", nbits); goto leave; @@ -112,7 +116,7 @@ for( ; j > 0; j-- ) { a = 0; for(; i < BYTES_PER_MPI_LIMB; i++ ) { - if (nread >= nmax) { + if (nread == nmax) { #ifdef M_DEBUG mpi_debug_free (val); #else