Package org.eclipse.jgit.errors

Examples of org.eclipse.jgit.errors.CorruptObjectException


      // We need to read here to enter the loop above and pump the
      // trailing checksum into the Inflater. It should return -1 as the
      // caller was supposed to consume all content.
      //
      if (read(skipBuffer) != -1 || actualSize != expectedSize) {
        throw new CorruptObjectException(MessageFormat.format(JGitText
            .get().packfileCorruptionDetected,
            JGitText.get().wrongDecompressedLength));
      }

      int used = bAvail - inf.getRemaining();
View Full Code Here


    //
    final byte[] hdr = new byte[20];
    IO.readFully(in, hdr, 0, 12);
    md.update(hdr, 0, 12);
    if (!is_DIRC(hdr))
      throw new CorruptObjectException(JGitText.get().notADIRCFile);
    final int ver = NB.decodeInt32(hdr, 4);
    boolean extended = false;
    if (ver == 3)
      extended = true;
    else if (ver != 2)
      throw new CorruptObjectException(MessageFormat.format(
          JGitText.get().unknownDIRCVersion, Integer.valueOf(ver)));
    entryCnt = NB.decodeInt32(hdr, 8);
    if (entryCnt < 0)
      throw new CorruptObjectException(JGitText.get().DIRCHasTooManyEntries);

    snapshot = FileSnapshot.save(liveFile);
    int smudge_s = (int) (snapshot.lastModified() / 1000);
    int smudge_ns = ((int) (snapshot.lastModified() % 1000)) * 1000000;

    // Load the individual file entries.
    //
    final int infoLength = DirCacheEntry.getMaximumInfoLength(extended);
    final byte[] infos = new byte[infoLength * entryCnt];
    sortedEntries = new DirCacheEntry[entryCnt];

    final MutableInteger infoAt = new MutableInteger();
    for (int i = 0; i < entryCnt; i++)
      sortedEntries[i] = new DirCacheEntry(infos, infoAt, in, md, smudge_s, smudge_ns);

    // After the file entries are index extensions, and then a footer.
    //
    for (;;) {
      in.mark(21);
      IO.readFully(in, hdr, 0, 20);
      if (in.read() < 0) {
        // No extensions present; the file ended where we expected.
        //
        break;
      }

      in.reset();
      md.update(hdr, 0, 8);
      IO.skipFully(in, 8);

      long sz = NB.decodeUInt32(hdr, 4);
      switch (NB.decodeInt32(hdr, 0)) {
      case EXT_TREE: {
        if (Integer.MAX_VALUE < sz) {
          throw new CorruptObjectException(MessageFormat.format(
              JGitText.get().DIRCExtensionIsTooLargeAt,
              formatExtensionName(hdr), Long.valueOf(sz)));
        }
        final byte[] raw = new byte[(int) sz];
        IO.readFully(in, raw, 0, raw.length);
        md.update(raw, 0, raw.length);
        tree = new DirCacheTree(raw, new MutableInteger(), null);
        break;
      }
      default:
        if (hdr[0] >= 'A' && hdr[0] <= 'Z') {
          // The extension is optional and is here only as
          // a performance optimization. Since we do not
          // understand it, we can safely skip past it, after
          // we include its data in our checksum.
          //
          skipOptionalExtension(in, md, hdr, sz);
        } else {
          // The extension is not an optimization and is
          // _required_ to understand this index format.
          // Since we did not trap it above we must abort.
          //
          throw new CorruptObjectException(MessageFormat.format(JGitText.get().DIRCExtensionNotSupportedByThisVersion
              , formatExtensionName(hdr)));
        }
      }
    }

    readIndexChecksum = md.digest();
    if (!Arrays.equals(readIndexChecksum, hdr)) {
      throw new CorruptObjectException(JGitText.get().DIRCChecksumMismatch);
    }
  }
View Full Code Here

    rawPtr = 0;
    nextIndex = 0;
    while (rawPtr < rawSize) {
      int c = raw[rawPtr++];
      if (c < '0' || c > '7')
        throw new CorruptObjectException(getId(), JGitText.get().corruptObjectInvalidEntryMode);
      int mode = c - '0';
      for (;;) {
        c = raw[rawPtr++];
        if (' ' == c)
          break;
        else if (c < '0' || c > '7')
          throw new CorruptObjectException(getId(), JGitText.get().corruptObjectInvalidMode);
        mode <<= 3;
        mode += c - '0';
      }

      int nameLen = 0;
      while (raw[rawPtr + nameLen] != 0)
        nameLen++;
      final byte[] name = new byte[nameLen];
      System.arraycopy(raw, rawPtr, name, 0, nameLen);
      rawPtr += nameLen + 1;

      final ObjectId id = ObjectId.fromRaw(raw, rawPtr);
      rawPtr += Constants.OBJECT_ID_LENGTH;

      final TreeEntry ent;
      if (FileMode.REGULAR_FILE.equals(mode))
        ent = new FileTreeEntry(this, id, name, false);
      else if (FileMode.EXECUTABLE_FILE.equals(mode))
        ent = new FileTreeEntry(this, id, name, true);
      else if (FileMode.TREE.equals(mode))
        ent = new Tree(this, id, name);
      else if (FileMode.SYMLINK.equals(mode))
        ent = new SymlinkTreeEntry(this, id, name);
      else if (FileMode.GITLINK.equals(mode))
        ent = new GitlinkTreeEntry(this, id, name);
      else
        throw new CorruptObjectException(getId(), MessageFormat.format(
            JGitText.get().corruptObjectInvalidMode2, Integer.toOctalString(mode)));
      temp[nextIndex++] = ent;
    }

    contents = temp;
View Full Code Here

    if (!biDirectionalPipe) {
      // Ensure the request was fully consumed. Any remaining input must
      // be a protocol error. If we aren't at EOF the implementation is broken.
      int eof = rawIn.read();
      if (0 <= eof)
        throw new CorruptObjectException(MessageFormat.format(
            JGitText.get().expectedEOFReceived,
            "\\x" + Integer.toHexString(eof))); //$NON-NLS-1$
    }

    if (sideband) {
View Full Code Here

    private byte[] inflate(PackedObjectInfo obj, long zpos, int sz)
        throws IOException, CorruptObjectException {
      try {
        return packOut.inflate(ctx, zpos, sz);
      } catch (DataFormatException dfe) {
        CorruptObjectException coe = new CorruptObjectException(
            MessageFormat.format(
                JGitText.get().objectAtHasBadZlibStream,
                Long.valueOf(obj.getOffset()),
                packDsc.getFileName(PackExt.PACK)));
        coe.initCause(dfe);
        throw coe;
      }
    }
View Full Code Here

   */
  public long findNextOffset(final long offset, final long maxOffset)
      throws CorruptObjectException {
    final int ith = binarySearch(offset);
    if (ith < 0)
      throw new CorruptObjectException(
          MessageFormat.format(
              JGitText.get().cantFindObjectInReversePackIndexForTheSpecifiedOffset,
              Long.valueOf(offset)));

    if (ith + 1 == nth.length)
View Full Code Here

            use(bAvail);

            p = fill(src, 1);
            inf.setInput(buf, p, bAvail);
          } else if (r == 0) {
            throw new CorruptObjectException(MessageFormat.format(
                JGitText.get().packfileCorruptionDetected,
                JGitText.get().unknownZlibError));
          }
        }
        actualSize += n;
        return 0 < n ? n : -1;
      } catch (DataFormatException dfe) {
        throw new CorruptObjectException(MessageFormat.format(JGitText
            .get().packfileCorruptionDetected, dfe.getMessage()));
      }
    }
View Full Code Here

      // We need to read here to enter the loop above and pump the
      // trailing checksum into the Inflater. It should return -1 as the
      // caller was supposed to consume all content.
      //
      if (read(skipBuffer) != -1 || actualSize != expectedSize) {
        throw new CorruptObjectException(MessageFormat.format(JGitText
            .get().packfileCorruptionDetected,
            JGitText.get().wrongDecompressedLength));
      }

      int used = bAvail - inf.getRemaining();
View Full Code Here

        in.reset();
        Inflater inf = wc.inflater();
        InputStream zIn = inflate(in, inf);
        int avail = readSome(zIn, hdr, 0, 64);
        if (avail < 5)
          throw new CorruptObjectException(id,
              JGitText.get().corruptObjectNoHeader);

        final MutableInteger p = new MutableInteger();
        int type = Constants.decodeTypeString(id, hdr, (byte) ' ', p);
        long size = RawParseUtils.parseLongBase10(hdr, p.value, p);
        if (size < 0)
          throw new CorruptObjectException(id,
              JGitText.get().corruptObjectNegativeSize);
        if (hdr[p.value++] != 0)
          throw new CorruptObjectException(id,
              JGitText.get().corruptObjectGarbageAfterSize);
        if (path == null && Integer.MAX_VALUE < size) {
          LargeObjectException.ExceedsByteArrayLimit e;
          e = new LargeObjectException.ExceedsByteArrayLimit();
          e.setObjectId(id);
          throw e;
        }
        if (size < wc.getStreamFileThreshold() || path == null) {
          byte[] data = new byte[(int) size];
          int n = avail - p.value;
          if (n > 0)
            System.arraycopy(hdr, p.value, data, 0, n);
          IO.readFully(zIn, data, n, data.length - n);
          checkValidEndOfStream(in, inf, id, hdr);
          return new ObjectLoader.SmallObject(type, data);
        }
        return new LargeObject(type, size, path, id, wc.db);

      } else {
        readSome(in, hdr, 2, 18);
        int c = hdr[0] & 0xff;
        int type = (c >> 4) & 7;
        long size = c & 15;
        int shift = 4;
        int p = 1;
        while ((c & 0x80) != 0) {
          c = hdr[p++] & 0xff;
          size += ((long) (c & 0x7f)) << shift;
          shift += 7;
        }

        switch (type) {
        case Constants.OBJ_COMMIT:
        case Constants.OBJ_TREE:
        case Constants.OBJ_BLOB:
        case Constants.OBJ_TAG:
          // Acceptable types for a loose object.
          break;
        default:
          throw new CorruptObjectException(id,
              JGitText.get().corruptObjectInvalidType);
        }

        if (path == null && Integer.MAX_VALUE < size) {
          LargeObjectException.ExceedsByteArrayLimit e;
          e = new LargeObjectException.ExceedsByteArrayLimit();
          e.setObjectId(id);
          throw e;
        }
        if (size < wc.getStreamFileThreshold() || path == null) {
          in.reset();
          IO.skipFully(in, p);
          Inflater inf = wc.inflater();
          InputStream zIn = inflate(in, inf);
          byte[] data = new byte[(int) size];
          IO.readFully(zIn, data, 0, data.length);
          checkValidEndOfStream(in, inf, id, hdr);
          return new ObjectLoader.SmallObject(type, data);
        }
        return new LargeObject(type, size, path, id, wc.db);
      }
    } catch (ZipException badStream) {
      throw new CorruptObjectException(id,
          JGitText.get().corruptObjectBadStream);
    }
  }
View Full Code Here

        in.reset();
        Inflater inf = wc.inflater();
        InputStream zIn = inflate(in, inf);
        int avail = readSome(zIn, hdr, 0, 64);
        if (avail < 5)
          throw new CorruptObjectException(id,
              JGitText.get().corruptObjectNoHeader);

        final MutableInteger p = new MutableInteger();
        Constants.decodeTypeString(id, hdr, (byte) ' ', p);
        long size = RawParseUtils.parseLongBase10(hdr, p.value, p);
        if (size < 0)
          throw new CorruptObjectException(id,
              JGitText.get().corruptObjectNegativeSize);
        return size;

      } else {
        readSome(in, hdr, 2, 18);
        int c = hdr[0] & 0xff;
        long size = c & 15;
        int shift = 4;
        int p = 1;
        while ((c & 0x80) != 0) {
          c = hdr[p++] & 0xff;
          size += ((long) (c & 0x7f)) << shift;
          shift += 7;
        }
        return size;
      }
    } catch (ZipException badStream) {
      throw new CorruptObjectException(id,
          JGitText.get().corruptObjectBadStream);
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.errors.CorruptObjectException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.