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

            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

    }

    try {
      return BinaryDelta.getResultSize(getDeltaHeader(ctx, deltaAt));
    } 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

              Collections.singleton(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

  public 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

            cnt -= n;
          }
        }
        if (crc1.getValue() != expectedCRC) {
          setCorrupt(src.offset);
          throw new CorruptObjectException(MessageFormat.format(
              JGitText.get().objectAtHasBadZlibStream,
              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,
              src.offset));
        }
        expectedCRC = crc1.getValue();
      } else {
        expectedCRC = -1;
      }
    } 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, 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, src.offset,
            getPackFile()));
      }
    }
  }
View Full Code Here

              Collections.singleton(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

      } 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.