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

Bug#280356: apt-cdrom handles long lines in sources.list poorly



On Mon, Nov 08, 2004 at 04:36:42PM -0500, Jeff Licquia wrote:

> When apt-cdrom rewrites sources.list to add a CD reference, it uses a
> 300-byte buffer to read lines from the old sources.list.  For some
> reason, if a line in sources.list is longer than 300 characters, the
> ifstream object used for reading gets confused.  Subsequent reads result
> in zero bytes being read.  Since we haven't reached EOF (there's still
> the rest of that line, at least, to read), and since we have lost the
> ability to read more data from the ifstream, the loop is infinite.
> 
> Moreover, newlines are stripped from the input sources.list, meaning
> that they have to be replaced on output.  Since we're reading zero bytes
> every time, we're writing a zero-byte string on every loop iteration
> followed by a newline.  This will continue until the disk on which
> sources.list exists is full.
> 
> I'm not sure if the bug is in apt or in libstdc++, since it is an
> ifstream that's acting badly, but since the behavior is easily
> duplicated in apt, that's where I'm filing.

Sounds nasty.  There is certainly some error checking missing there, but I
don't see why it should loop.  If it runs out of buffer space, the next read
should just get the rest of the line.  However, it sounds like the error bit
is being set on the stream, so that we can't read from it anymore after this
happens.

I can't find a reference either way, as to whether it is correct to be
setting the error bit, but it is easy enough to work around if that's what's
happening (I haven't tested).  If you could add a simple "if (!F) { error
and break }" after the getline, that should clear up your problem if my
hunch is correct.

-- 
 - mdz



Reply to: