<feed xmlns='http://www.w3.org/2005/Atom'>
<title>apt/ftparchive/contents.cc, branch 3.3.0</title>
<subtitle>Debians commandline package manager</subtitle>
<id>https://git.kalnischkies.de/apt/atom?h=3.3.0</id>
<link rel='self' href='https://git.kalnischkies.de/apt/atom?h=3.3.0'/>
<link rel='alternate' type='text/html' href='https://git.kalnischkies.de/apt/'/>
<updated>2024-10-07T14:17:32Z</updated>
<entry>
<title>ftparchive: contents: Avoid exponential complexity and overflows</title>
<updated>2024-10-07T14:17:32Z</updated>
<author>
<name>Julian Andres Klode</name>
<email>julian.klode@canonical.com</email>
</author>
<published>2024-10-04T16:35:15Z</published>
<link rel='alternate' type='text/html' href='https://git.kalnischkies.de/apt/commit/?id=604d1fac652965ec71629fec09ca39660c8bb8dc'/>
<id>urn:sha1:604d1fac652965ec71629fec09ca39660c8bb8dc</id>
<content type='text'>
Wstored directory entries as a binary tree, but we did not balance it,
leading to exponential complexity on insertion and potentially
exponential levels of stack recursion in DoPrint(), causing overflows.

Simply use an std::set storing pairs of (path, package) instead,
this is very simple, and handles aspects such as ordering or the
same package appearing multiple times correctly.

Iteration becomes a bit tricky: After seeing (file1, pkg1) when
we see (file1, pkg2) we need to append pkg2 to the current line;
once we see (file2, anything), we need write out the line and
start a new one.

For memory optimization, we use a new class StringInBlock to handle
the block-managed C strings generated by Mystrdup() in a type-safe
manner. This ensures proper lifetime of objects and no accidental
conversions to std::string. This saves a significant amount of
space (a pair of std::string is 64-byte large; a pair of pointers
is 16 byte large, a 48 byte saving per entry); reproducing the Contents
file of Ubuntu 24.10, using straight-forward std::string resulted in
GB of memory usage, whereas the C-style string only uses 1.35 GB.

As a side effect of the patch we also remove arbitrary 1024-byte
buffer sizes. There also is a change in output: The package names
are now sorted alphabetically, instead of being in visit order.

LP: #2083697
</content>
</entry>
<entry>
<title>ftparchive: Mystrdup: Add safety check and bump buffer size</title>
<updated>2024-10-07T14:02:06Z</updated>
<author>
<name>Julian Andres Klode</name>
<email>julian.klode@canonical.com</email>
</author>
<published>2024-10-07T13:55:44Z</published>
<link rel='alternate' type='text/html' href='https://git.kalnischkies.de/apt/commit/?id=d61d86c73104d1aa84fd6ca506c2230e67727b17'/>
<id>urn:sha1:d61d86c73104d1aa84fd6ca506c2230e67727b17</id>
<content type='text'>
Add a safety check to ensure that the block were are allocating
actually fits the string we want to write. If it doesn't, abort
the program.

While we are here, bump the buffer size from 40 KiB to 4 MiB,
because why bother with smaller buffers.
</content>
</entry>
<entry>
<title>Modernize standard library includes</title>
<updated>2024-02-20T12:49:04Z</updated>
<author>
<name>Julian Andres Klode</name>
<email>julian.klode@canonical.com</email>
</author>
<published>2024-02-20T12:43:08Z</published>
<link rel='alternate' type='text/html' href='https://git.kalnischkies.de/apt/commit/?id=40a75722c43ae24cb9a99d6730a3b25b65819c49'/>
<id>urn:sha1:40a75722c43ae24cb9a99d6730a3b25b65819c49</id>
<content type='text'>
This was automated with sed and git-clang-format, and then I had to
fix up the top of policy.cc by hand as git-clang-format accidentally
indented it by two spaces.
</content>
</entry>
<entry>
<title>Apply various suggestions by cppcheck</title>
<updated>2019-07-08T13:51:17Z</updated>
<author>
<name>David Kalnischkies</name>
<email>david@kalnischkies.de</email>
</author>
<published>2019-07-08T13:48:59Z</published>
<link rel='alternate' type='text/html' href='https://git.kalnischkies.de/apt/commit/?id=2b734a7ec429825c7007c1093883229e069d36c7'/>
<id>urn:sha1:2b734a7ec429825c7007c1093883229e069d36c7</id>
<content type='text'>
Reported-By: cppcheck
</content>
</entry>
<entry>
<title>Remove obsolete RCS keywords</title>
<updated>2018-05-07T11:41:31Z</updated>
<author>
<name>Guillem Jover</name>
<email>guillem@debian.org</email>
</author>
<published>2018-05-06T20:32:41Z</published>
<link rel='alternate' type='text/html' href='https://git.kalnischkies.de/apt/commit/?id=164f1b78d1849a0f33df7352875f86e28f5de06a'/>
<id>urn:sha1:164f1b78d1849a0f33df7352875f86e28f5de06a</id>
<content type='text'>
Prompted-by: Jakub Wilk &lt;jwilk@debian.org&gt;
</content>
</entry>
<entry>
<title>fix various typos reported by spellintian</title>
<updated>2017-01-19T14:59:38Z</updated>
<author>
<name>David Kalnischkies</name>
<email>david@kalnischkies.de</email>
</author>
<published>2017-01-19T14:14:19Z</published>
<link rel='alternate' type='text/html' href='https://git.kalnischkies.de/apt/commit/?id=93cff633a830e222693fc0f3d78e6e534d1126ee'/>
<id>urn:sha1:93cff633a830e222693fc0f3d78e6e534d1126ee</id>
<content type='text'>
Most of them in (old) code comments. The two instances of user visible
string changes the po files of the manpages are fixed up as well.

Gbp-Dch: Ignore
Reported-By: spellintian
</content>
</entry>
<entry>
<title>apply various suggestions made by cppcheck</title>
<updated>2015-11-05T11:21:33Z</updated>
<author>
<name>David Kalnischkies</name>
<email>david@kalnischkies.de</email>
</author>
<published>2015-11-04T20:08:55Z</published>
<link rel='alternate' type='text/html' href='https://git.kalnischkies.de/apt/commit/?id=258b9e512c4001e806c5c0966acecd3d742ec6e9'/>
<id>urn:sha1:258b9e512c4001e806c5c0966acecd3d742ec6e9</id>
<content type='text'>
Reported-By: cppcheck
Git-Dch: Ignore
</content>
</entry>
<entry>
<title>rewrite all TFRewrite instances to use the new pkgTagSection::Write</title>
<updated>2015-05-11T15:22:33Z</updated>
<author>
<name>David Kalnischkies</name>
<email>david@kalnischkies.de</email>
</author>
<published>2015-05-11T13:08:08Z</published>
<link rel='alternate' type='text/html' href='https://git.kalnischkies.de/apt/commit/?id=88593886a42025d51d76051da5929b044e42efee'/>
<id>urn:sha1:88593886a42025d51d76051da5929b044e42efee</id>
<content type='text'>
While it is mostly busywork to rewrite all instances it actually fixes
bugs as the data storage used by the new method is std::string rather
than a char*, the later mostly created by c_str() from a std::string
which the caller has to ensure keeps in scope – something apt-ftparchive
actually didn't ensure and relied on copy-on-write behavior instead
which c++11 forbids and hence the new default gcc abi doesn't use it.
</content>
</entry>
<entry>
<title>fix: warning: extra ‘;’ [-Wpedantic]</title>
<updated>2014-09-26T22:11:15Z</updated>
<author>
<name>David Kalnischkies</name>
<email>david@kalnischkies.de</email>
</author>
<published>2014-09-26T20:55:56Z</published>
<link rel='alternate' type='text/html' href='https://git.kalnischkies.de/apt/commit/?id=bf3ad91fdf4967fe107e08a6887f9ed51f4f5eea'/>
<id>urn:sha1:bf3ad91fdf4967fe107e08a6887f9ed51f4f5eea</id>
<content type='text'>
Reported-By: gcc -Wpedantic
Git-Dch: Ignore
</content>
</entry>
<entry>
<title>use free() instead of delete() when realloc is used</title>
<updated>2014-05-27T14:25:43Z</updated>
<author>
<name>Michael Vogt</name>
<email>mvo@debian.org</email>
</author>
<published>2014-05-27T14:25:43Z</published>
<link rel='alternate' type='text/html' href='https://git.kalnischkies.de/apt/commit/?id=21ea1dbb50176a89e7f456f9b31220ff3097fdf2'/>
<id>urn:sha1:21ea1dbb50176a89e7f456f9b31220ff3097fdf2</id>
<content type='text'>
ContentsExtract::~ContentsExtract() needs to use free() because
Data got allocated via realloc()

Reported-By: clang -fsanitize=address -fno-omit-frame-pointer
</content>
</entry>
</feed>
