StringIndexOutOfBoundsException in HelpFormatter.findWrapPos

Bug #944546 reported by Andrew
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
libcommons-cli-java (Ubuntu)
Fix Released
High
James Page
Precise
Won't Fix
High
James Page

Bug Description

This bug has been fixed upstream in version 1.3 Could you look at backporting this fix or updating to the latest version?

https://issues.apache.org/jira/browse/CLI-193

"You should be able to get it to throw with a call like this:

findWrapPos( "hello", 3, 0 ); // should return -1

The exception gets thrown whenever the passed-in string does not contain any spaces, tabs, or newlines. It looks like line 914 was also expecting line 908 to have a <.

Also, I think there are other bugs. In this call:

findWrapPos( "helloooo\noo\ngoodbye", 6, 7 ); // should return 8

we want it to short circuit and return the first newline if there is one in the substring starting at 7 with width 6 ("o\noo\ng"), and so it should return the index of the first '\n', which is 8. However, on lines 876 and 877, it's doing "pos <= width", instead of "pos <= startPos+width", so it won't return, and it will end up (incorrectly, I think) returning the index of the second newline's position. And once you fix lines 876 and 877, it's going to return 9 instead of 8, which I think is incorrect. The other return statements return pos, not pos+1, and I think line 879 should do the same."

Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Andrew, thanks for the report!

Patch looks pretty minimal and its an upstream critical bug. This should definitely be fixed before precise releases.

Changed in libcommons-cli-java (Ubuntu):
status: New → Triaged
importance: Undecided → Critical
Changed in libcommons-cli-java (Ubuntu Precise):
milestone: none → ubuntu-12.04-beta-2
tags: added: rls-mgr-p-tracking
Revision history for this message
Kate Stewart (kate.stewart) wrote :

Not seeing much progress on this, assigning explicitly to server team to consider.

Changed in libcommons-cli-java (Ubuntu Precise):
assignee: nobody → Ubuntu Server Team (ubuntu-server)
Martin Pitt (pitti)
Changed in libcommons-cli-java (Ubuntu Precise):
milestone: ubuntu-12.04-beta-2 → ubuntu-12.04
James Page (james-page)
Changed in libcommons-cli-java (Ubuntu Precise):
milestone: ubuntu-12.04 → ubuntu-12.04.1
Changed in libcommons-cli-java (Ubuntu):
milestone: ubuntu-12.04 → quantal-alpha-1
Changed in libcommons-cli-java (Ubuntu Precise):
assignee: Ubuntu Server Team (ubuntu-server) → James Page (james-page)
Changed in libcommons-cli-java (Ubuntu):
assignee: Ubuntu Server Team (ubuntu-server) → James Page (james-page)
Revision history for this message
James Page (james-page) wrote :

Applying this patch results in a regression in the junit test suite provided for this package.

Changed in libcommons-cli-java (Ubuntu Precise):
importance: Critical → High
Changed in libcommons-cli-java (Ubuntu):
importance: Critical → High
Revision history for this message
James Page (james-page) wrote :

Actually that seems to be an issue with openjdk-7 - builds just fine on openjdk-6 and passes all tests.

Changed in libcommons-cli-java (Ubuntu):
status: Triaged → In Progress
Changed in libcommons-cli-java (Ubuntu):
milestone: quantal-alpha-1 → quantal-alpha-2
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package libcommons-cli-java - 1.2-3ubuntu1

---------------
libcommons-cli-java (1.2-3ubuntu1) quantal; urgency=low

  * d/patches/CLI-193.patch: Cherry picked patch from upstream VCS
    to ensure that wrap width is never exceeded when printing help
    messages which can result in exceptions (LP: #944546).
  * d/build.properties: Fix test source directory location and enable
    test suite execution during build process.
 -- James Page <email address hidden> Tue, 19 Jun 2012 15:00:56 +0100

Changed in libcommons-cli-java (Ubuntu):
status: In Progress → Fix Released
Revision history for this message
James Page (james-page) wrote :

Andrew

Do you have a specific test case which exhibits this issue in Ubuntu 12.04? I can re-produce using a artificial test case but I would prefer to have a concrete issue with an installed package to support the SRU.

Marking task for precise 'Incomplete' pending your response; please set back to new when you have provided the requested information.

Thanks

Changed in libcommons-cli-java (Ubuntu Precise):
status: Triaged → Incomplete
Revision history for this message
James Page (james-page) wrote :

mkdir classes
javac -d classes -classpath /usr/share/java/commons-cli.jar TestCLIFailure.java
java -classpath /usr/share/java/commons-cli.jar:classes org.apache.commons.cli.TestCLIFailure
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5
 at java.lang.String.charAt(String.java:695)
 at org.apache.commons.cli.HelpFormatter.findWrapPos(HelpFormatter.java:904)
 at org.apache.commons.cli.TestCLIFailure.main(TestCLIFailure.java:8)

James Page (james-page)
Changed in libcommons-cli-java (Ubuntu Precise):
status: Incomplete → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.