Package org.eclipse.jgit.errors

Examples of org.eclipse.jgit.errors.CorruptObjectException


    }

    try {
      return BinaryDelta.getResultSize(getDeltaHeader(curs, deltaAt));
    } catch (DataFormatException e) {
      throw new CorruptObjectException(MessageFormat.format(JGitText
          .get().objectAtHasBadZlibStream, pos, getPackFile()));
    }
  }
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 += (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 += (c & 0x7f) << shift;
          shift += 7;
        }
        return size;
      }
    } catch (ZipException badStream) {
      throw new CorruptObjectException(id,
          JGitText.get().corruptObjectBadStream);
    }
  }
View Full Code Here

    for (;;) {
      int r;
      try {
        r = inf.inflate(buf);
      } catch (DataFormatException e) {
        throw new CorruptObjectException(id,
            JGitText.get().corruptObjectBadStream);
      }
      if (r != 0)
        throw new CorruptObjectException(id,
            JGitText.get().corruptObjectIncorrectLength);

      if (inf.finished()) {
        if (inf.getRemaining() != 0 || in.read() != -1)
          throw new CorruptObjectException(id,
              JGitText.get().corruptObjectBadStream);
        break;
      }

      if (!inf.needsInput())
        throw new CorruptObjectException(id,
            JGitText.get().corruptObjectBadStream);

      r = in.read(buf);
      if (r <= 0)
        throw new CorruptObjectException(id,
            JGitText.get().corruptObjectBadStream);
      inf.setInput(buf, 0, r);
    }
  }
View Full Code Here

          int r = super.read(b, off, cnt);
          if (r > 0)
            remaining -= r;
          return r;
        } catch (ZipException badStream) {
          throw new CorruptObjectException(id,
              JGitText.get().corruptObjectBadStream);
        }
      }

      @Override
View Full Code Here

    private void read(ByteBuffer buf) throws CorruptObjectException {
      signature = buf.getInt();
      version = buf.getInt();
      entries = buf.getInt();
      if (signature != 0x44495243)
        throw new CorruptObjectException(MessageFormat.format(
            JGitText.get().indexSignatureIsInvalid, signature));
      if (version != 2)
        throw new CorruptObjectException(MessageFormat.format(
            JGitText.get().unknownIndexVersionOrCorruptIndex, version));
    }
View Full Code Here

      case 'b':
        if (typeString[position + 1] != 'l'
            || typeString[position + 2] != 'o'
            || typeString[position + 3] != 'b'
            || typeString[position + 4] != endMark)
          throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
        offset.value = position + 5;
        return Constants.OBJ_BLOB;

      case 'c':
        if (typeString[position + 1] != 'o'
            || typeString[position + 2] != 'm'
            || typeString[position + 3] != 'm'
            || typeString[position + 4] != 'i'
            || typeString[position + 5] != 't'
            || typeString[position + 6] != endMark)
          throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
        offset.value = position + 7;
        return Constants.OBJ_COMMIT;

      case 't':
        switch (typeString[position + 1]) {
        case 'a':
          if (typeString[position + 2] != 'g'
              || typeString[position + 3] != endMark)
            throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
          offset.value = position + 4;
          return Constants.OBJ_TAG;

        case 'r':
          if (typeString[position + 2] != 'e'
              || typeString[position + 3] != 'e'
              || typeString[position + 4] != endMark)
            throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
          offset.value = position + 5;
          return Constants.OBJ_TREE;

        default:
          throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
        }

      default:
        throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
      }
    } catch (ArrayIndexOutOfBoundsException bad) {
      throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
    }
  }
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

    //
    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, ver));
    entryCnt = NB.decodeInt32(hdr, 8);
    if (entryCnt < 0)
      throw new CorruptObjectException(JGitText.get().DIRCHasTooManyEntries);

    // 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);
    snapshot = FileSnapshot.save(liveFile);

    // 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), 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)));
        }
      }
    }

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

              use(bAvail);

              p = fill(src, 1);
              inf.setInput(buf, p, bAvail);
            } else {
              throw new CorruptObjectException(
                  MessageFormat
                      .format(
                          JGitText.get().packfileCorruptionDetected,
                          JGitText.get().unknownZlibError));
            }
          } else {
            n += r;
          }
        }
        actualSize += n;
        return 0 < n ? n : -1;
      } catch (DataFormatException dfe) {
        throw new CorruptObjectException(MessageFormat.format(JGitText
            .get().packfileCorruptionDetected, dfe.getMessage()));
      }
    }
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.