Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8168111

A jar file can be persuaded to include itself as an entry

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 7
    • tools
    • None
    • jar

      Colleague Max Kanat-Alexander reports:

      You can get the jar command to add an already-existing version of a jar to the jar file itself by using -C. This is because the check on "zname" in addFile does not normalize paths to remove "." as a directory entry.

      The only reason that this doesn't cause an infinite loop is an accident of the order in which the current code iterates through the entries that it is going to add (an order which is not guaranteed by the APIs it is using to iterate). If you change that order, then you do get an infinite loop.

      Here's a repro:

      (set -eux; D=$(mktemp -d); ( cd $D && mkdir foo && touch foo/file && jar cMf foo/test.jar -C foo/ . && jar tf foo/test.jar && jar cMf foo/test.jar -C foo/ . && jar tf foo/test.jar ); rm -rf $D)
      +/bin/zsh:6> D=+/bin/zsh:6> mktemp -d
      +/bin/zsh:6> D=/tmp/tmp.KS4EAnsvjE
      +/bin/zsh:6> cd /tmp/tmp.KS4EAnsvjE
      +chpwd:1> [[ 10797 != 136379 ]]
      +chpwd:2> unfunction chpwd
      +/bin/zsh:6> mkdir foo
      +/bin/zsh:6> touch foo/file
      +/bin/zsh:6> jar cMf foo/test.jar -C foo/ .
      +/bin/zsh:6> jar tf foo/test.jar
      file
      +/bin/zsh:6> jar cMf foo/test.jar -C foo/ .
      +/bin/zsh:6> jar tf foo/test.jar
      test.jar
      file
      +/bin/zsh:6> rm -rf /tmp/tmp.KS4EAnsvjE

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: