squid icon indicating copy to clipboard operation
squid copied to clipboard

Bug 5029: assertion failed: MemBuf.cc: new_cap > capacity

Open yadij opened this issue 2 years ago • 1 comments

Since v4 the code converting URL-rewrite helper replies from legacy Squid-2 syntax. Allocated a temporary MemBuf sized to be exactly the response I/O size. This did not allow for MemBuf::append use of grow() to ensure there is always free space in the MemBuf and later code possibly using terminate() to make the buffer a c-string.

Use new C++11 MemBuf initialization to remove the max capacity limitation on this temporary buffer and add +1 to the initial size so the first allocation does not need to grow() in order to terminate().

yadij avatar Aug 10 '21 13:08 yadij

I doubt the current changes address the problem the reporter was actually suffering from, but they do fix another problem and can be improved to address both.

A scan of the code shows some other places initializing MemBuf in a way which might trigger this assertion under edge-case inputs: src/fs/rock/RockRebuild.cc: buf.init(SM_PAGE_SIZE, SM_PAGE_SIZE); src/fs/ufs/RebuildState.cc: buf.init(SM_PAGE_SIZE, SM_PAGE_SIZE); src/fs/ufs/UFSSwapDir.cc: buf.init(header.record_size, header.record_size);

These look like trouble, but avoid asserting by allocating a buffer capacity +1 larger than what will be append()ed later: src/MemStore.cc: mb.init(buf.length+1, buf.length+1); src/helper/Reply.cc: empty.init(1, 1); src/servers/FtpServer.cc: mb.init(data.length + 1, data.length + 1);

yadij avatar Aug 12 '21 11:08 yadij