Uploaded image for project: 'UIMA'
  1. UIMA
  2. UIMA-210

faulty use of .read(buffer...) in several places - not checking for fewer than expected bytes/chars read

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1
    • 2.1
    • Core Java Framework
    • None

    Description

      The definition of most instances of stream.read(bufferArray) says it reads up to the length of the array. We had earlier an issue on a multi-core machine where the length read was much less than the length of the buffer or of the file. (This was in Vinci). The solution is to wrap these things in code that looks like this from the XTalkTransporter (this assumes the file length is known):

      static public void readFully(byte[] b, int length, InputStream in) throws IOException {
      int read_so_far = 0;
      while (read_so_far < length) {
      int count = in.read(b, read_so_far, length - read_so_far);
      if (count < 0)

      { throw new EOFException(); }

      read_so_far += count;
      }
      }

      Code which is broken can be found by scanning for .read(

      Ones I found scanning are:
      VinciTAEClient
      FileUtils (copyFile method)
      (Note: similarly named class FileUtil (no final "s") has a copyFile method that is OK)

      XMLUtil.java has fragment that could fail incorrectly in detectXmlFileEncoding:
      // store the 1st text byte and read next 6 bytes of XML file
      buffer[byteCounter++] = (byte) nextByte;
      if (iStream.read(buffer, byteCounter, bytes2put - 1) != bytes2put - 1) //ERROR NOT ALLOWING FOR FEWER BYTES READ
      throw new IOException("cannot read file");

      There are multiple instances of code in JcasSofaTest don't allow for the possiblity of reading fewer than buf size; here's one:
      dest = new byte[4];
      is.close();
      is = intArrayView.getSofaDataStream();
      assertTrue(is != null);
      int i = 0;
      while (is.read(dest) != -1)

      { assertTrue(ByteBuffer.wrap(dest).getInt() == intArrayFS.get(i++)); ; }

      And another one like this in SofaTest.

      DebugControlThread method doCheckpoint has the problem

      In our examples, the following have the problem:
      CasMultiplierExampleApplication
      FileSystemCollectionReader
      ExampleApplication
      PrintAnnotations

      JetExpander

      And in uimaj-tools:
      FileSystemCollectionReader
      CasTreeViewer

      Attachments

        Activity

          People

            schor Marshall Schor
            schor Marshall Schor
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: