private void VerifyLooseObject(AnyObjectId id, byte[] compressed)
        {
            UnpackedObjectLoader uol;

            try
            {
                uol = new UnpackedObjectLoader(compressed);
            }
            catch (CorruptObjectException parsingError)
            {
                // Some HTTP servers send back a "200 OK" status with an HTML
                // page that explains the requested file could not be found.
                // These servers are most certainly misconfigured, but many
                // of them exist in the world, and many of those are hosting
                // Git repositories.
                //
                // Since an HTML page is unlikely to hash to one of our loose
                // objects we treat this condition as a FileNotFoundException
                // and attempt to recover by getting the object from another
                // source.
                //
                var e = new FileNotFoundException(id.Name, parsingError);
                throw e;
            }

            _objectDigest.Reset();
            _objectDigest.Update(Constants.encodedTypeString(uol.Type));
            _objectDigest.Update((byte)' ');
            _objectDigest.Update(Constants.encodeASCII(uol.Size));
            _objectDigest.Update(0);
            _objectDigest.Update(uol.CachedBytes);
            _idBuffer.FromRaw(_objectDigest.Digest(), 0);

            if (!AnyObjectId.equals(id, _idBuffer))
            {
                throw new TransportException("Incorrect hash for " + id.Name + "; computed " + _idBuffer.Name + " as a " +
                                             Constants.typeString(uol.Type) + " from " + compressed.Length +
                                             " bytes.");
            }
            if (_objCheck != null)
            {
                try
                {
                    _objCheck.check(uol.Type, uol.CachedBytes);
                }
                catch (CorruptObjectException e)
                {
                    throw new TransportException("Invalid " + Constants.typeString(uol.Type) + " " + id.Name + ": " + e.Message);
                }
            }
        }
Ejemplo n.º 2
0
        private void VerifyLooseObject(AnyObjectId id, byte[] compressed)
        {
            UnpackedObjectLoader uol;

            try
            {
                uol = new UnpackedObjectLoader(compressed);
            }
            catch (CorruptObjectException parsingError)
            {
                var e = new FileNotFoundException(id.Name, parsingError);
                throw e;
            }

            _objectDigest.Reset();
            _objectDigest.Update(Constants.encodedTypeString(uol.Type));
            _objectDigest.Update((byte)' ');
            _objectDigest.Update(Constants.encodeASCII(uol.Size));
            _objectDigest.Update(0);
            _objectDigest.Update(uol.CachedBytes);
            _idBuffer.FromRaw(_objectDigest.Digest(), 0);

            if (!id.Equals(_idBuffer))
            {
                throw new TransportException("Incorrect hash for " + id.Name + "; computed " + _idBuffer.Name + " as a " +
                                             Constants.typeString(uol.Type) + " from " + compressed.Length +
                                             " bytes.");
            }
            if (_objCheck != null)
            {
                try
                {
                    _objCheck.check(uol.Type, uol.CachedBytes);
                }
                catch (CorruptObjectException e)
                {
                    throw new TransportException("Invalid " + Constants.typeString(uol.Type) + " " + id.Name + ": " + e.Message);
                }
            }
        }
Ejemplo n.º 3
0
        private void VerifyLooseObject(AnyObjectId id, byte[] compressed)
        {
            UnpackedObjectLoader uol;
            try
            {
                uol = new UnpackedObjectLoader(compressed);
            }
            catch (CorruptObjectException parsingError)
            {
                var e = new FileNotFoundException(id.Name, parsingError);
                throw e;
            }

            _objectDigest.Reset();
            _objectDigest.Update(Constants.encodedTypeString(uol.Type));
            _objectDigest.Update((byte)' ');
            _objectDigest.Update(Constants.encodeASCII(uol.Size));
            _objectDigest.Update(0);
            _objectDigest.Update(uol.CachedBytes);
            _idBuffer.FromRaw(_objectDigest.Digest(), 0);

            if (!id.Equals(_idBuffer))
            {
                throw new TransportException("Incorrect hash for " + id.Name + "; computed " + _idBuffer.Name + " as a " +
                                             Constants.typeString(uol.Type) + " from " + compressed.Length +
                                             " bytes.");
            }
            if (_objCheck != null)
            {
                try
                {
                    _objCheck.check(uol.Type, uol.CachedBytes);
                }
                catch (CorruptObjectException e)
                {
                    throw new TransportException("Invalid " + Constants.typeString(uol.Type) + " " + id.Name + ": " + e.Message);
                }
            }
        }
Ejemplo n.º 4
0
        private void VerifyLooseObject(AnyObjectId id, byte[] compressed)
        {
            UnpackedObjectLoader uol;
            try
            {
                uol = new UnpackedObjectLoader(compressed);
            }
            catch (CorruptObjectException parsingError)
            {
                // Some HTTP servers send back a "200 OK" status with an HTML
                // page that explains the requested file could not be found.
                // These servers are most certainly misconfigured, but many
                // of them exist in the world, and many of those are hosting
                // Git repositories.
                //
                // Since an HTML page is unlikely to hash to one of our loose
                // objects we treat this condition as a FileNotFoundException
                // and attempt to recover by getting the object from another
                // source.
                //
                var e = new FileNotFoundException(id.Name, parsingError);
                throw e;
            }

            _objectDigest.Reset();
            _objectDigest.Update(Constants.encodedTypeString(uol.Type));
            _objectDigest.Update((byte)' ');
            _objectDigest.Update(Constants.encodeASCII(uol.Size));
            _objectDigest.Update(0);
            _objectDigest.Update(uol.CachedBytes);
            _idBuffer.FromRaw(_objectDigest.Digest(), 0);

            if (!AnyObjectId.equals(id, _idBuffer))
            {
                throw new TransportException("Incorrect hash for " + id.Name + "; computed " + _idBuffer.Name + " as a " +
                                             Constants.typeString(uol.Type) + " from " + compressed.Length +
                                             " bytes.");
            }
            if (_objCheck != null)
            {
                try
                {
                    _objCheck.check(uol.Type, uol.CachedBytes);
                }
                catch (CorruptObjectException e)
                {
                    throw new TransportException("Invalid " + Constants.typeString(uol.Type) + " " + id.Name + ": " + e.Message);
                }
            }
        }