public virtual void TestMaxObjectSizeFullBlob()
        {
            TestRepository d = new TestRepository <FileRepository>(db);

            byte[] data = Constants.Encode("0123456789");
            d.Blob(data);
            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
            PackHeader(pack, 1);
            pack.Write((Constants.OBJ_BLOB) << 4 | 10);
            Deflate(pack, data);
            Digest(pack);
            PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray()));

            p.SetMaxObjectSizeLimit(11);
            p.Parse(NullProgressMonitor.INSTANCE);
            p = Index(new ByteArrayInputStream(pack.ToByteArray()));
            p.SetMaxObjectSizeLimit(10);
            p.Parse(NullProgressMonitor.INSTANCE);
            p = Index(new ByteArrayInputStream(pack.ToByteArray()));
            p.SetMaxObjectSizeLimit(9);
            try
            {
                p.Parse(NullProgressMonitor.INSTANCE);
                NUnit.Framework.Assert.Fail("PackParser should have failed");
            }
            catch (TooLargeObjectInPackException e)
            {
                NUnit.Framework.Assert.IsTrue(e.Message.Contains("10"));
                // obj size
                NUnit.Framework.Assert.IsTrue(e.Message.Contains("9"));
            }
        }
        public virtual void TestMaxObjectSizeDeltaResultSize()
        {
            TestRepository d = new TestRepository <FileRepository>(db);
            RevBlob        a = d.Blob("0123456789");

            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
            PackHeader(pack, 1);
            pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4);
            a.CopyRawTo(pack);
            Deflate(pack, new byte[] { 10, 11, 1, (byte)('a') });
            Digest(pack);
            PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray()));

            p.SetAllowThin(true);
            p.SetMaxObjectSizeLimit(11);
            p.Parse(NullProgressMonitor.INSTANCE);
            p = Index(new ByteArrayInputStream(pack.ToByteArray()));
            p.SetAllowThin(true);
            p.SetMaxObjectSizeLimit(10);
            try
            {
                p.Parse(NullProgressMonitor.INSTANCE);
                NUnit.Framework.Assert.Fail("PackParser should have failed");
            }
            catch (TooLargeObjectInPackException e)
            {
                NUnit.Framework.Assert.IsTrue(e.Message.Contains("11"));
                // result obj size
                NUnit.Framework.Assert.IsTrue(e.Message.Contains("10"));
            }
        }
Beispiel #3
0
        /// <exception cref="System.IO.IOException"></exception>
        private void VerifyOpenPack(bool thin)
        {
            byte[] packData = os.ToByteArray();
            if (thin)
            {
                PackParser p = Index(packData);
                try
                {
                    p.Parse(NullProgressMonitor.INSTANCE);
                    NUnit.Framework.Assert.Fail("indexer should grumble about missing object");
                }
                catch (IOException)
                {
                }
            }
            // expected
            ObjectDirectoryPackParser p_1 = (ObjectDirectoryPackParser)Index(packData);

            p_1.SetKeepEmpty(true);
            p_1.SetAllowThin(thin);
            p_1.SetIndexVersion(2);
            p_1.Parse(NullProgressMonitor.INSTANCE);
            pack = p_1.GetPackFile();
            NUnit.Framework.Assert.IsNotNull(pack, "have PackFile after parsing");
        }
Beispiel #4
0
 /// <exception cref="NGit.Errors.TransportException"></exception>
 protected internal override void DoFetch(ProgressMonitor monitor, ICollection <Ref
                                                                                > want, ICollection <ObjectId> have)
 {
     VerifyPrerequisites();
     try
     {
         ObjectInserter ins = transport.local.NewObjectInserter();
         try
         {
             PackParser parser = ins.NewPackParser(bin);
             parser.SetAllowThin(true);
             parser.SetObjectChecking(transport.IsCheckFetchedObjects());
             parser.SetLockMessage(lockMessage);
             packLock = parser.Parse(NullProgressMonitor.INSTANCE);
             ins.Flush();
         }
         finally
         {
             ins.Release();
         }
     }
     catch (IOException err)
     {
         Close();
         throw new TransportException(transport.uri, err.Message, err);
     }
     catch (RuntimeException err)
     {
         Close();
         throw new TransportException(transport.uri, err.Message, err);
     }
 }
        public virtual void TestDataAfterPackFooterSplitHeaderRead()
        {
            TestRepository d = new TestRepository <FileRepository>(db);

            byte[]  data    = Constants.Encode("a");
            RevBlob b       = d.Blob(data);
            int     objects = 248;

            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(32 * 1024);
            PackHeader(pack, objects + 1);
            int           offset = 13;
            StringBuilder sb     = new StringBuilder();

            for (int i = 0; i < offset; i++)
            {
                sb.Append(i);
            }
            offset = sb.ToString().Length;
            int lenByte = (Constants.OBJ_BLOB) << 4 | (offset & unchecked ((int)(0x0F)));

            offset >>= 4;
            if (offset > 0)
            {
                lenByte |= 1 << 7;
            }
            pack.Write(lenByte);
            while (offset > 0)
            {
                lenByte  = offset & unchecked ((int)(0x7F));
                offset >>= 6;
                if (offset > 0)
                {
                    lenByte |= 1 << 7;
                }
                pack.Write(lenByte);
            }
            Deflate(pack, Constants.Encode(sb.ToString()));
            for (int i_1 = 0; i_1 < objects; i_1++)
            {
                // The last pack header written falls across the 8192 byte boundary
                // between [8189:8210]
                pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4);
                b.CopyRawTo(pack);
                Deflate(pack, new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked (
                                               (int)(0x1)), (byte)('b') });
            }
            Digest(pack);
            byte[] packData   = pack.ToByteArray();
            byte[] streamData = new byte[packData.Length + 1];
            System.Array.Copy(packData, 0, streamData, 0, packData.Length);
            streamData[packData.Length] = unchecked ((int)(0x7e));
            InputStream @in = new ByteArrayInputStream(streamData);
            PackParser  p   = Index(@in);

            p.SetAllowThin(true);
            p.SetCheckEofAfterPackFooter(false);
            p.SetExpectDataAfterPackFooter(true);
            p.Parse(NullProgressMonitor.INSTANCE);
            NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x7e)), @in.Read());
        }
        public virtual void TestDataAfterPackFooterSplitObjectRead()
        {
            byte[] data = Constants.Encode("0123456789");
            // Build a pack ~17k
            int objects = 900;

            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(32 * 1024);
            PackHeader(pack, objects);
            for (int i = 0; i < objects; i++)
            {
                pack.Write((Constants.OBJ_BLOB) << 4 | 10);
                Deflate(pack, data);
            }
            Digest(pack);
            byte[] packData   = pack.ToByteArray();
            byte[] streamData = new byte[packData.Length + 1];
            System.Array.Copy(packData, 0, streamData, 0, packData.Length);
            streamData[packData.Length] = unchecked ((int)(0x7e));
            InputStream @in = new ByteArrayInputStream(streamData);
            PackParser  p   = Index(@in);

            p.SetAllowThin(true);
            p.SetCheckEofAfterPackFooter(false);
            p.SetExpectDataAfterPackFooter(true);
            p.Parse(NullProgressMonitor.INSTANCE);
            NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x7e)), @in.Read());
        }
        public virtual void TestDataAfterPackFooterSingleRead()
        {
            TestRepository d = new TestRepository <FileRepository>(db);
            RevBlob        a = d.Blob("a");

            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(32 * 1024);
            PackHeader(pack, 1);
            pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4);
            a.CopyRawTo(pack);
            Deflate(pack, new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked (
                                           (int)(0x1)), (byte)('b') });
            Digest(pack);
            byte[] packData   = pack.ToByteArray();
            byte[] streamData = new byte[packData.Length + 1];
            System.Array.Copy(packData, 0, streamData, 0, packData.Length);
            streamData[packData.Length] = unchecked ((int)(0x7e));
            InputStream @in = new ByteArrayInputStream(streamData);
            PackParser  p   = Index(@in);

            p.SetAllowThin(true);
            p.SetCheckEofAfterPackFooter(false);
            p.SetExpectDataAfterPackFooter(true);
            p.Parse(NullProgressMonitor.INSTANCE);
            NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x7e)), @in.Read());
        }
        public virtual void TestNonMarkingInputStream()
        {
            TestRepository d = new TestRepository <FileRepository>(db);
            RevBlob        a = d.Blob("a");

            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
            PackHeader(pack, 1);
            pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4);
            a.CopyRawTo(pack);
            Deflate(pack, new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked (
                                           (int)(0x1)), (byte)('b') });
            Digest(pack);
            InputStream @in = new _ByteArrayInputStream_319(pack.ToByteArray());
            PackParser  p   = Index(@in);

            p.SetAllowThin(true);
            p.SetCheckEofAfterPackFooter(false);
            p.SetExpectDataAfterPackFooter(true);
            try
            {
                p.Parse(NullProgressMonitor.INSTANCE);
                NUnit.Framework.Assert.Fail("PackParser should have failed");
            }
            catch (IOException e)
            {
                NUnit.Framework.Assert.AreEqual(e.Message, JGitText.Get().inputStreamMustSupportMark
                                                );
            }
        }
        public virtual void TestPackWithTrailingGarbage()
        {
            TestRepository d = new TestRepository <FileRepository>(db);
            RevBlob        a = d.Blob("a");

            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
            PackHeader(pack, 1);
            pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4);
            a.CopyRawTo(pack);
            Deflate(pack, new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked (
                                           (int)(0x1)), (byte)('b') });
            Digest(pack);
            PackParser p = Index(new UnionInputStream(new ByteArrayInputStream(pack.ToByteArray
                                                                                   ()), new ByteArrayInputStream(new byte[] { unchecked ((int)(0x7e)) })));

            p.SetAllowThin(true);
            p.SetCheckEofAfterPackFooter(true);
            try
            {
                p.Parse(NullProgressMonitor.INSTANCE);
                NUnit.Framework.Assert.Fail("Pack with trailing garbage was accepted");
            }
            catch (IOException err)
            {
                NUnit.Framework.Assert.AreEqual(MessageFormat.Format(JGitText.Get().expectedEOFReceived
                                                                     , "\\x7e"), err.Message);
            }
        }
        /// <exception cref="System.IO.IOException"></exception>
        private void ReceivePack(ProgressMonitor monitor)
        {
            OnReceivePack();
            InputStream input = @in;

            if (sideband)
            {
                input = new SideBandInputStream(input, monitor, GetMessageWriter());
            }
            ObjectInserter ins = local.NewObjectInserter();

            try
            {
                PackParser parser = ins.NewPackParser(input);
                parser.SetAllowThin(thinPack);
                parser.SetObjectChecking(transport.IsCheckFetchedObjects());
                parser.SetLockMessage(lockMessage);
                packLock = parser.Parse(monitor);
                ins.Flush();
            }
            finally
            {
                ins.Release();
            }
        }
Beispiel #11
0
        public virtual void TestDelta_SmallObjectChain()
        {
            ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
            byte[] data0 = new byte[512];
            Arrays.Fill(data0, unchecked ((byte)unchecked ((int)(0xf3))));
            ObjectId id0 = fmt.IdFor(Constants.OBJ_BLOB, data0);

            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64 * 1024);
            PackHeader(pack, 4);
            ObjectHeader(pack, Constants.OBJ_BLOB, data0.Length);
            Deflate(pack, data0);
            byte[]   data1  = Clone(unchecked ((int)(0x01)), data0);
            byte[]   delta1 = Delta(data0, data1);
            ObjectId id1    = fmt.IdFor(Constants.OBJ_BLOB, data1);

            ObjectHeader(pack, Constants.OBJ_REF_DELTA, delta1.Length);
            id0.CopyRawTo(pack);
            Deflate(pack, delta1);
            byte[]   data2  = Clone(unchecked ((int)(0x02)), data1);
            byte[]   delta2 = Delta(data1, data2);
            ObjectId id2    = fmt.IdFor(Constants.OBJ_BLOB, data2);

            ObjectHeader(pack, Constants.OBJ_REF_DELTA, delta2.Length);
            id1.CopyRawTo(pack);
            Deflate(pack, delta2);
            byte[]   data3  = Clone(unchecked ((int)(0x03)), data2);
            byte[]   delta3 = Delta(data2, data3);
            ObjectId id3    = fmt.IdFor(Constants.OBJ_BLOB, data3);

            ObjectHeader(pack, Constants.OBJ_REF_DELTA, delta3.Length);
            id2.CopyRawTo(pack);
            Deflate(pack, delta3);
            Digest(pack);
            PackParser ip = Index(pack.ToByteArray());

            ip.SetAllowThin(true);
            ip.Parse(NullProgressMonitor.INSTANCE);
            NUnit.Framework.Assert.IsTrue(wc.Has(id3), "has blob");
            ObjectLoader ol = wc.Open(id3);

            NUnit.Framework.Assert.IsNotNull(ol, "created loader");
            NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, ol.GetType());
            NUnit.Framework.Assert.AreEqual(data3.Length, ol.GetSize());
            NUnit.Framework.Assert.IsFalse(ol.IsLarge(), "is large");
            NUnit.Framework.Assert.IsNotNull(ol.GetCachedBytes());
            CollectionAssert.AreEquivalent(data3, ol.GetCachedBytes());
            ObjectStream @in = ol.OpenStream();

            NUnit.Framework.Assert.IsNotNull(@in, "have stream");
            NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, @in.GetType());
            NUnit.Framework.Assert.AreEqual(data3.Length, @in.GetSize());
            byte[] act = new byte[data3.Length];
            IOUtil.ReadFully(@in, act, 0, data3.Length);
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, data3), "same content");
            NUnit.Framework.Assert.AreEqual(-1, @in.Read(), "stream at EOF");
            @in.Close();
        }
        /// <exception cref="System.IO.IOException"></exception>
        private void OpenPack(TemporaryBuffer.Heap buf)
        {
            if (inserter == null)
            {
                inserter = src.NewObjectInserter();
            }
            byte[]     raw = buf.ToByteArray();
            PackParser p   = inserter.NewPackParser(new ByteArrayInputStream(raw));

            p.SetAllowThin(true);
            p.Parse(PM);
        }
        public virtual void TestPackWithDuplicateBlob()
        {
            byte[] data = Constants.Encode("0123456789abcdefg");
            TestRepository <Repository> d = new TestRepository <Repository>(db);

            NUnit.Framework.Assert.IsTrue(db.HasObject(d.Blob(data)));
            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
            PackHeader(pack, 1);
            pack.Write((Constants.OBJ_BLOB) << 4 | unchecked ((int)(0x80)) | 1);
            pack.Write(1);
            Deflate(pack, data);
            Digest(pack);
            PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray()));

            p.SetAllowThin(false);
            p.Parse(NullProgressMonitor.INSTANCE);
        }
        public virtual void TestTinyThinPack()
        {
            TestRepository d = new TestRepository <FileRepository>(db);
            RevBlob        a = d.Blob("a");

            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
            PackHeader(pack, 1);
            pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4);
            a.CopyRawTo(pack);
            Deflate(pack, new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked (
                                           (int)(0x1)), (byte)('b') });
            Digest(pack);
            PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray()));

            p.SetAllowThin(true);
            p.Parse(NullProgressMonitor.INSTANCE);
        }
Beispiel #15
0
            /// <exception cref="System.IO.IOException"></exception>
            internal virtual void DownloadPack(ProgressMonitor monitor)
            {
                string name = "pack/" + this.packName;

                WalkRemoteObjectDatabase.FileStream s = this.connection.Open(name);
                PackParser parser = this._enclosing.inserter.NewPackParser(s.@in);

                parser.SetAllowThin(false);
                parser.SetObjectChecker(this._enclosing.objCheck);
                parser.SetLockMessage(this._enclosing.lockMessage);
                PackLock Lock = parser.Parse(monitor);

                if (Lock != null)
                {
                    this._enclosing.packLocks.AddItem(Lock);
                }
                this._enclosing.inserter.Flush();
            }