[jcifs] Patch: SocketOutputStream bugfix

Thomas Krammer TKrammer at nxn-software.com
Wed Feb 5 06:08:11 EST 2003


Hi,

I've found a bug in the SocketOutputStream.write() method. If len is in the
range [1501, 1503] an ArrayIndexOutOfBoundsException is thrown. That's
because 4 bytes in the buffer are reserved for the package header which
isn't taken into account when the method checks if it needs to create a
temporary buffer.

This problem occured during my tests because the last WriteAndX block of a
transfer was exactly 1501 bytes long.

The following patch fixes the problem:

*** jcifs_0.7.1\src\jcifs\netbios\SocketOutputStream.java	Wed Jan 15
21:56:44 2003
--- jcifs_0.7.1_mod\src\jcifs\netbios\SocketOutputStream.java	Tue Feb 04
18:14:47 2003
***************
*** 54,60 ****
          bufr[count++] = (byte)b;
      }
      public synchronized void write( byte[] b, int off, int len ) throws
IOException {
!         if( len >= bufr.length ) {
              Log.println( Log.WARNINGS, "session service warning",
                              "write len exceeds pre-allocated buffer size;
performance " +
                              "will suffer: len=" + len + ",writeSize=" +
writeSize );
--- 54,60 ----
          bufr[count++] = (byte)b;
      }
      public synchronized void write( byte[] b, int off, int len ) throws
IOException {
!         if( len + 4 > bufr.length ) {
              Log.println( Log.WARNINGS, "session service warning",
                              "write len exceeds pre-allocated buffer size;
performance " +
                              "will suffer: len=" + len + ",writeSize=" +
writeSize );


More information about the jcifs mailing list