Package org.eclipse.jgit.errors

Examples of org.eclipse.jgit.errors.CorruptObjectException


              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


      // 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

    // protocols that embed a pack stream are required to either end their
    // stream with the pack, or embed the pack with a framing system like
    // the SideBandInputStream does.

    if (bAvail != 0)
      throw new CorruptObjectException(MessageFormat.format(
          JGitText.get().expectedEOFReceived,
          "\\x" + Integer.toHexString(buf[bOffset] & 0xff)));

    if (isCheckEofAfterPackFooter()) {
      int eof = in.read();
      if (0 <= eof)
        throw new CorruptObjectException(MessageFormat.format(
            JGitText.get().expectedEOFReceived,
            "\\x" + Integer.toHexString(eof)));
    }

    if (!Arrays.equals(actHash, srcHash))
      throw new CorruptObjectException(
          JGitText.get().corruptObjectPackfileChecksumIncorrect);

    onPackFooter(srcHash);
  }
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)));
    }

    if (sideband) {
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)));
        }
      }
    }

    readIndexChecksum = md.digest();
    if (!Arrays.equals(readIndexChecksum, hdr)) {
      throw new CorruptObjectException(JGitText.get().DIRCChecksumMismatch);
    }
  }
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

        case TYPE_GITLINK:
          continue;

        default:
          throw new CorruptObjectException(MessageFormat.format(
              JGitText.get().corruptObjectInvalidMode3,
              String.format("%o", mode), idBuffer.name(),
              RawParseUtils.decode(buf, tv.namePtr, tv.nameEnd),
              tv.obj));
        }
View Full Code Here

      case TYPE_GITLINK:
        break;

      default:
        idBuffer.fromRaw(raw, ptr);
        throw new CorruptObjectException(MessageFormat.format(JGitText
            .get().corruptObjectInvalidMode3, String.format("%o",
            mode), idBuffer.name(), "", tree));
      }
      ptr += ID_SZ;
    }
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

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.