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

Avoid potential NPE by using Path#getParentPath API in hadoop-huaweicloud

VotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.4.0
    • Component/s: fs

      Description

      Hello,
      Our code analyses found a following potential NPE:

       

      public Path getParent() {
          String path = uri.getPath();
          int lastSlash = path.lastIndexOf('/');
          int start = startPositionWithoutWindowsDrive(path);
          if ((path.length() == start) ||               // empty path
              (lastSlash == start && path.length() == start+1)) { // at root
            return null; <--- Null returned
          }
      

       

      private static void getDirectories(final String key, final String sourceKey,
            final Set<String> directories) {
          Path p = new Path(key);
          Path sourcePath = new Path(sourceKey);
          // directory must add first
          if (key.endsWith("/") && p.compareTo(sourcePath) > 0) {
            directories.add(p.toString());
          }
          while (p.compareTo(sourcePath) > 0) {
            p = p.getParent(); <--- NPE
            if (p.isRoot() || p.compareTo(sourcePath) == 0) {
              break;
            }
      

      Given a root path, it will lead to NPE at method getDirectories

       

      Full trace:

       

      1. Return null to caller
      https://github.com/apache/hadoop/blob/f40e3eb0590f85bb42d2471992bf5d524628fdd6/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java#L432

      2. Function getParent executes and returns
      https://github.com/apache/hadoop/blob/f40e3eb0590f85bb42d2471992bf5d524628fdd6/hadoop-cloud-storage-project/hadoop-huaweicloud/src/main/java/org/apache/hadoop/fs/obs/OBSObjectBucketUtils.java#L875

      3. The return value of function getParent is passed as the this pointer to function isRoot (the return value of function getParent can be null)
      https://github.com/apache/hadoop/blob/f40e3eb0590f85bb42d2471992bf5d524628fdd6/hadoop-cloud-storage-project/hadoop-huaweicloud/src/main/java/org/apache/hadoop/fs/obs/OBSObjectBucketUtils.java#L876

      Commit: f40e3eb0590f85bb42d2471992bf5d524628fdd6

        Attachments

          Activity

            People

            • Assignee:
              vjasani Viraj Jasani
              Reporter:
              ErrReporter Error Reporter

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 2h
                2h

                  Issue deployment