Bug#572596: python-apt: TagSection corruption when iterating through a TagFile
Am Donnerstag, den 04.03.2010, 19:01 -0700 schrieb John Wright:
> Package: python-apt
> Version: 0.7.93.3
> Severity: important
>
> Hello,
>
> While trying to convert deb822 in python-debian to use the TagParser
> iterator API (rather than an ugly hack to avoid using shared storage), I
> ran into this little bug. It seems that after somewhere between 30 or
> 40 paragraphs (I assume this depends on the size of the paragraphs), old
> section instances become corrupt.
Well, it seems that while the tag section is a new object, the buffer is
actually stored in the TagFile and not the TagSection. It seems that I
missed this during my tests.
Attached you find the patch I just committed as revision 366 to the
debian-sid branch.
--
Julian Andres Klode - Debian Developer, Ubuntu Member
See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.
=== modified file 'debian/changelog'
--- debian/changelog 2010-03-03 18:40:22 +0000
+++ debian/changelog 2010-03-05 17:11:36 +0000
@@ -4,6 +4,9 @@ python-apt (0.7.93.4) unstable; urgency=
- Add AcquireItem.partialsize member.
* python/generic.cc:
- Map UntranslatedDepType to dep_type_untranslated.
+ * python/tag.cc:
+ - Hack the TagFile iterator to not use shared storage (Closes: #572596):
+ Scan once, duplicate the section data, and scan again.
* apt/package.py:
- Create a string class BaseDependency.__dstr which makes '>' equal to
'>>' and '<' equal to '<<' (compatibility).
=== modified file 'python/tag.cc'
--- python/tag.cc 2010-02-27 16:31:39 +0000
+++ python/tag.cc 2010-03-05 17:12:39 +0000
@@ -271,6 +271,22 @@ static PyObject *TagFileNext(PyObject *S
Obj.Section->Data = 0;
if (Obj.Object.Step(Obj.Section->Object) == false)
return HandleErrors(NULL);
+
+ // Bug-Debian: http://bugs.debian.org/572596
+ // Duplicate the data here and scan the duplicated section data; in order
+ // to not use any shared storage.
+ // TODO: Provide an API in apt-pkg to do this; this is really ugly.
+
+ // Fetch old section data
+ const char *Start;
+ const char *Stop;
+ Obj.Section->Object.GetSection(Start,Stop);
+ // Duplicate the data
+ Obj.Section->Data = new char[Stop-Start];
+ strncpy(Obj.Section->Data, Start, Stop-Start);
+ // Rescan it
+ Obj.Section->Object.Scan(Obj.Section->Data, Stop-Start);
+
Py_INCREF(Obj.Section);
return HandleErrors(Obj.Section);
}
Reply to: