[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#400874: [patch] proposed fix



Hi,

sorry for being coming in so late. Here is a patch that should fix the
problem by making the buffer grow dynamically. Please give it testing.

Just to double the buffersize does only buy us time, the code that
deals with BigBuf is broken in serveral ways. 

Cheers,
 Michael
diff -Nru /tmp/PbNjE929IO/apt-0.6.46.3/apt-pkg/deb/debsrcrecords.cc /tmp/g7pQUgTOK3/apt-0.6.46.4/apt-pkg/deb/debsrcrecords.cc
--- /tmp/PbNjE929IO/apt-0.6.46.3/apt-pkg/deb/debsrcrecords.cc	2006-03-02 13:44:28.000000000 +0000
+++ /tmp/g7pQUgTOK3/apt-0.6.46.4/apt-pkg/deb/debsrcrecords.cc	2006-12-04 09:00:01.000000000 +0000
@@ -18,6 +18,8 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/configuration.h>
+
+using std::max;
 									/*}}}*/
 
 // SrcRecordParser::Binaries - Return the binaries field		/*{{{*/
@@ -34,31 +36,20 @@
    if (Bins.empty() == true || Bins.length() >= 102400)
       return 0;
    
-   // Workaround for #236688.  Only allocate a new buffer if the field
-   // is large, to avoid a performance penalty
-   char *BigBuf = NULL;
-   char *Buf;
-   if (Bins.length() > sizeof(Buffer))
-   {
-      BigBuf = new char[Bins.length()];
-      Buf = BigBuf;
-   }
-   else
+   if (Bins.length() >= BufSize)
    {
-      Buf = Buffer;
+      delete [] Buffer;
+      // allocate new size based on buffer (but never smaller than 4000)
+      BufSize = max((unsigned long)4000, 
+		    max((unsigned long)Bins.length()+1,2*BufSize));
+      Buffer = new char[BufSize];
    }
 
-   strcpy(Buf,Bins.c_str());
-   if (TokSplitString(',',Buf,StaticBinList,
+   strcpy(Buffer,Bins.c_str());
+   if (TokSplitString(',',Buffer,StaticBinList,
 		      sizeof(StaticBinList)/sizeof(StaticBinList[0])) == false)
-   {
-      if (BigBuf != NULL)
-         delete BigBuf;
       return 0;
-   }
 
-   if (BigBuf != NULL)
-      delete BigBuf;
    return (const char **)StaticBinList;
 }
 									/*}}}*/
diff -Nru /tmp/PbNjE929IO/apt-0.6.46.3/apt-pkg/deb/debsrcrecords.h /tmp/g7pQUgTOK3/apt-0.6.46.4/apt-pkg/deb/debsrcrecords.h
--- /tmp/PbNjE929IO/apt-0.6.46.3/apt-pkg/deb/debsrcrecords.h	2006-03-02 13:44:28.000000000 +0000
+++ /tmp/g7pQUgTOK3/apt-0.6.46.4/apt-pkg/deb/debsrcrecords.h	2006-12-04 08:54:43.000000000 +0000
@@ -24,9 +24,10 @@
    FileFd Fd;
    pkgTagFile Tags;
    pkgTagSection Sect;
-   char Buffer[10000];
    char *StaticBinList[400];
    unsigned long iOffset;
+   char *Buffer;
+   unsigned long BufSize;
    
    public:
 
@@ -49,10 +50,9 @@
    };
    virtual bool Files(vector<pkgSrcRecords::File> &F);
 
-   debSrcRecordParser(string File,pkgIndexFile const *Index) :
-                   Parser(Index),      
-                   Fd(File,FileFd::ReadOnly),
-                   Tags(&Fd,102400) {};
+   debSrcRecordParser(string File,pkgIndexFile const *Index) 
+      : Parser(Index), Fd(File,FileFd::ReadOnly), Tags(&Fd,102400), 
+        Buffer(0), BufSize(0) {}
 };
 
 #endif

Reply to: