Uploaded image for project: 'Hadoop Common'
  1. Hadoop Common
  2. HADOOP-3454

Text.find incorrectly searches beyond the end of the buffer

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.17.0
    • 0.18.0
    • None
    • None
    • Reviewed

    Description

      Text.find() does not pay attention to the length field. So, this code:

          public void testTextFind()
          {
              Text t = new Text("FIND AN I");
              t.set(new byte[] { (byte) 'F' });
      
              assert t.getLength() == 1 : "Length should be 1";
              assert t.find( "F") == 0 : "Found F at " + t.find("F");
              assert t.find( "I") == -1 : "Found I at " + t.find("I");
          }
      

      incorrectly throws an assertion because it finds the I at position 1, even though the Text is only one byte long.

      I think to fix this it is enough to change this line in Text.find:

      ByteBuffer src = ByteBuffer.wrap(this.bytes);

      to

      ByteBuffer src = ByteBuffer.wrap(this.bytes,0,this.length);

      Attachments

        1. HADOOP-3454.patch
          1 kB
          Chad Whipkey

        Activity

          People

            cwhipkey Chad Whipkey
            cwhipkey Chad Whipkey
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: