Package org.eclipse.jgit.errors

Examples of org.eclipse.jgit.errors.CorruptObjectException


      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);
    lastModified = liveFile.lastModified();

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

    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

  long findNextOffset(final long offset, final long maxOffset)
      throws CorruptObjectException {
    if (offset <= Integer.MAX_VALUE) {
      final int i32 = Arrays.binarySearch(offsets32, (int) offset);
      if (i32 < 0)
        throw new CorruptObjectException(MessageFormat.format(
            JGitText.get().cantFindObjectInReversePackIndexForTheSpecifiedOffset
            , offset));

      if (i32 + 1 == offsets32.length) {
        if (offsets64.length > 0)
          return offsets64[0];
        return maxOffset;
      }
      return offsets32[i32 + 1];
    } else {
      final int i64 = Arrays.binarySearch(offsets64, offset);
      if (i64 < 0)
        throw new CorruptObjectException(MessageFormat.format(
            JGitText.get().cantFindObjectInReversePackIndexForTheSpecifiedOffset
            , offset));

      if (i64 + 1 == offsets64.length)
        return maxOffset;
View Full Code Here

          redoSearchForReuse(otp);
          continue;
        } else {
          // Object writing already started, we cannot recover.
          //
          CorruptObjectException coe;
          coe = new CorruptObjectException(otp, "");
          coe.initCause(gone);
          throw coe;
        }
      }
    }
View Full Code Here

        default:
          if (FileMode.GITLINK.equals(mode))
            continue;
          treeWalk.getObjectId(idBuffer, 0);
          throw new CorruptObjectException(MessageFormat.format(JGitText.get().invalidModeFor
              , mode, idBuffer.name(), treeWalk.getPathString(), obj.getId().name()));
        }
      }
    } catch (IOException ioe) {
      throw new TransportException(MessageFormat.format(JGitText.get().cannotReadTree, obj.name()), ioe);
View Full Code Here

      }
      default:
        if (FileMode.GITLINK.equals(mode))
          continue;
        treeWalk.getObjectId(idBuffer, 0);
        throw new CorruptObjectException(MessageFormat.format(JGitText.get().corruptObjectInvalidMode3
            , mode, idBuffer.name(), treeWalk.getPathString(), tree.name()));
      }
    }
  }
View Full Code Here

            cnt -= n;
          }
        }
        if (crc1.getValue() != expectedCRC) {
          setCorrupt(src.offset);
          throw new CorruptObjectException(MessageFormat.format(
              JGitText.get().objectAtHasBadZlibStream,
              src.offset, getPackFile()));
        }
      } else {
        // We don't have a CRC32 code in the index, so compute it
        // now while inflating the raw data to get zlib to tell us
        // whether or not the data is safe.
        //
        Inflater inf = curs.inflater();
        byte[] tmp = new byte[1024];
        if (quickCopy != null) {
          quickCopy.check(inf, tmp, dataOffset, (int) dataLength);
        } else {
          long pos = dataOffset;
          long cnt = dataLength;
          while (cnt > 0) {
            final int n = (int) Math.min(cnt, buf.length);
            readFully(pos, buf, 0, n, curs);
            crc1.update(buf, 0, n);
            inf.setInput(buf, 0, n);
            while (inf.inflate(tmp, 0, tmp.length) > 0)
              continue;
            pos += n;
            cnt -= n;
          }
        }
        if (!inf.finished() || inf.getBytesRead() != dataLength) {
          setCorrupt(src.offset);
          throw new EOFException(MessageFormat.format(
              JGitText.get().shortCompressedStreamAt,
              src.offset));
        }
        expectedCRC = crc1.getValue();
      }
    } catch (DataFormatException dataFormat) {
      setCorrupt(src.offset);

      CorruptObjectException corruptObject = new CorruptObjectException(
          MessageFormat.format(
              JGitText.get().objectAtHasBadZlibStream,
              src.offset, getPackFile()));
      corruptObject.initCause(dataFormat);

      StoredObjectRepresentationNotAvailableException gone;
      gone = new StoredObjectRepresentationNotAvailableException(src);
      gone.initCause(corruptObject);
      throw gone;

    } catch (IOException ioError) {
      StoredObjectRepresentationNotAvailableException gone;
      gone = new StoredObjectRepresentationNotAvailableException(src);
      gone.initCause(ioError);
      throw gone;
    }

    if (quickCopy != null) {
      // The entire object fits into a single byte array window slice,
      // and we have it pinned.  Write this out without copying.
      //
      out.writeHeader(src, inflatedLength);
      quickCopy.write(out, dataOffset, (int) dataLength);

    } else if (dataLength <= buf.length) {
      // Tiny optimization: Lots of objects are very small deltas or
      // deflated commits that are likely to fit in the copy buffer.
      //
      out.writeHeader(src, inflatedLength);
      out.write(buf, 0, (int) dataLength);
    } else {
      // Now we are committed to sending the object. As we spool it out,
      // check its CRC32 code to make sure there wasn't corruption between
      // the verification we did above, and us actually outputting it.
      //
      out.writeHeader(src, inflatedLength);
      long pos = dataOffset;
      long cnt = dataLength;
      while (cnt > 0) {
        final int n = (int) Math.min(cnt, buf.length);
        readFully(pos, buf, 0, n, curs);
        crc2.update(buf, 0, n);
        out.write(buf, 0, n);
        pos += n;
        cnt -= n;
      }
      if (crc2.getValue() != expectedCRC) {
        throw new CorruptObjectException(MessageFormat.format(JGitText
            .get().objectAtHasBadZlibStream, src.offset,
            getPackFile()));
      }
    }
  }
View Full Code Here

      } while (delta != null);

      return new ObjectLoader.SmallObject(type, data);

    } catch (DataFormatException dfe) {
      CorruptObjectException coe = new CorruptObjectException(
          MessageFormat.format(
              JGitText.get().objectAtHasBadZlibStream, pos,
              getPackFile()));
      coe.initCause(dfe);
      throw coe;
    }
  }
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.