Martin Leese
2009-Jul-22 03:47 UTC
[ogg-dev] Fixing ogg vorbis corruption caused by bad metadata
Adam Rosi-Kessel <adam at rosi-kessel.org> wrote:> I finally got something like an explanation from the Mediamonkey > developers. Here is their explanation as to why MM corrupted my files: > > > the problem was caused by the fact that Vorbis library uses alloca() > > function on several places, which allocates memory on stack. We > > changed it to alloc() and free() functions pair instead, which fixes > > the problem. I suppose that it can easily happen to any other > > application using Vorbis library, but the real problem depends on > > stack settings of the particular application. In any case, I think it > > might make sense for Vorbis developers to make this change. > > I'm not sure exactly what to make of this, but it sounds perhaps like a > stack overflow issue?I once got corruption similar to what you saw, but in a non-audio setting. This was in back in the 1990s. What happened was that I wrote code that allocated memory to a pointer, freed it, allocated memory to a second pointer, but continued to use the first pointer. This meant that two pointers were now both pointing to the same chunk of memory. One possibility is that MediaMonkey messed up the free()s, like I did in the last century. Anyway, calling alloc()s with no corresponding free()s is a memory leak. Not good code. Regards, Martin -- Martin J Leese E-mail: martin.leese stanfordalumni.org Web: http://members.tripod.com/martin_leese/
Erik de Castro Lopo
2009-Jul-22 03:51 UTC
[ogg-dev] Fixing ogg vorbis corruption caused by bad metadata
Martin Leese wrote:> Anyway, calling alloc()s with no corresponding > free()s is a memory leak. Not good code.The alloca() function allocates space on the stack and that allocation is automatically freed when the function that did the allocation returns. The Linux man page is quite informative. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
Adam Rosi-Kessel
2009-Jul-22 13:43 UTC
[ogg-dev] Fixing ogg vorbis corruption caused by bad metadata
Erik de Castro Lopo wrote, on 7/21/2009 11:51 PM:>> Anyway, calling alloc()s with no corresponding >> free()s is a memory leak. Not good code. > The alloca() function allocates space on the stack and > that allocation is automatically freed when the function > that did the allocation returns. > > The Linux man page is quite informative.So it sounds like this should be a vorbis bug insofar as the libraries are coded with a function that is buggy under Windows, which could be fixed relatively easily by switching to alloc/free calls instead? Other Windows clients using these libraries could presumably cause the same corruption that I had.