Package org.eclipse.jgit.errors

Examples of org.eclipse.jgit.errors.CorruptObjectException


    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

      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

            cnt -= n;
          }
        }
        if (crc1.getValue() != expectedCRC) {
          setCorrupt(src.offset);
          throw new CorruptObjectException(MessageFormat.format(
              JGitText.get().objectAtHasBadZlibStream,
              Long.valueOf(src.offset), getPackFile()));
        }
      } else if (validate) {
        // 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,
              Long.valueOf(src.offset)));
        }
        expectedCRC = crc1.getValue();
      } else {
        expectedCRC = -1;
      }
    } catch (DataFormatException dataFormat) {
      setCorrupt(src.offset);

      CorruptObjectException corruptObject = new CorruptObjectException(
          MessageFormat.format(
              JGitText.get().objectAtHasBadZlibStream,
              Long.valueOf(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, null);

    } 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.
      //
      if (!validate) {
        long pos = dataOffset;
        long cnt = dataLength;
        while (cnt > 0) {
          final int n = (int) Math.min(cnt, buf.length);
          readFully(pos, buf, 0, n, curs);
          pos += n;
          cnt -= n;
        }
      }
      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);
        if (validate)
          crc2.update(buf, 0, n);
        out.write(buf, 0, n);
        pos += n;
        cnt -= n;
      }
      if (validate && crc2.getValue() != expectedCRC) {
        throw new CorruptObjectException(MessageFormat.format(
            JGitText.get().objectAtHasBadZlibStream,
            Long.valueOf(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,
              Long.valueOf(pos), getPackFile()));
      coe.initCause(dfe);
      throw coe;
    }
  }
View Full Code Here

    }

    try {
      return BinaryDelta.getResultSize(getDeltaHeader(curs, deltaAt));
    } catch (DataFormatException e) {
      throw new CorruptObjectException(MessageFormat.format(
          JGitText.get().objectAtHasBadZlibStream, Long.valueOf(pos),
          getPackFile()));
    }
  }
View Full Code Here

    final byte[] srcHash = new byte[20];
    System.arraycopy(buf, c, srcHash, 0, 20);
    use(20);

    if (bAvail != 0 && !expectDataAfterPackFooter)
      throw new CorruptObjectException(MessageFormat.format(
          JGitText.get().expectedEOFReceived,
          "\\x" + Integer.toHexString(buf[bOffset] & 0xff))); //$NON-NLS-1$
    if (isCheckEofAfterPackFooter()) {
      int eof = in.read();
      if (0 <= eof)
        throw new CorruptObjectException(MessageFormat.format(
            JGitText.get().expectedEOFReceived,
            "\\x" + Integer.toHexString(eof))); //$NON-NLS-1$
    } else if (bAvail > 0 && expectDataAfterPackFooter) {
      in.reset();
      IO.skipFully(in, bOffset);
    }

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

    onPackFooter(srcHash);
  }
View Full Code Here

      final byte[] data) throws IOException {
    if (objCheck != null) {
      try {
        objCheck.check(type, data);
      } catch (CorruptObjectException e) {
        throw new CorruptObjectException(MessageFormat.format(
            JGitText.get().invalidObject,
            Constants.typeString(type),
            readCurs.abbreviate(id, 10).name(),
            e.getMessage()), e);
      }
View Full Code Here

            cnt -= n;
          }
        }
        if (crc1.getValue() != expectedCRC) {
          setCorrupt(src.offset);
          throw new CorruptObjectException(MessageFormat.format(
              JGitText.get().objectAtHasBadZlibStream,
              Long.valueOf(src.offset), getPackName()));
        }
      } else if (validate) {
        // 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 = ctx.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, ctx);
            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,
              Long.valueOf(src.offset)));
        }
        expectedCRC = crc1.getValue();
      } else {
        expectedCRC = -1;
      }
    } catch (DataFormatException dataFormat) {
      setCorrupt(src.offset);

      CorruptObjectException corruptObject = new CorruptObjectException(
          MessageFormat.format(
              JGitText.get().objectAtHasBadZlibStream,
              Long.valueOf(src.offset), getPackName()));
      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, null);

    } 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.
      //
      if (!validate) {
        long pos = dataOffset;
        long cnt = dataLength;
        while (cnt > 0) {
          final int n = (int) Math.min(cnt, buf.length);
          readFully(pos, buf, 0, n, ctx);
          pos += n;
          cnt -= n;
        }
      }
      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, ctx);
        if (validate)
          crc2.update(buf, 0, n);
        out.write(buf, 0, n);
        pos += n;
        cnt -= n;
      }
      if (validate && crc2.getValue() != expectedCRC) {
        throw new CorruptObjectException(MessageFormat.format(
            JGitText.get().objectAtHasBadZlibStream,
            Long.valueOf(src.offset), getPackName()));
      }
    }
  }
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, Long.valueOf(pos),
              getPackName()));
      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.