[mythtv] Backend SEGV
Marcus Metzler
mocm at mocm.de
Wed Mar 1 14:12:41 UTC 2006
>>>>> "Daniel" == Daniel Kristjansson <danielk at cuymedia.net> writes:
Daniel> On Wed, 2006-03-01 at 13:31 +0000, Stuart Auchterlonie
Daniel> wrote:
>> I'm having the backend segfault on 9218. I believe it's
>> related to [9214] as it is attempting to covert the ServiceName
>> to a string using dvb_decode_text rather than the old
>> copy. dvb_decode_text can't find a codec to decode this and
>> returns a NULL codec.
Daniel> Can you try SVN?
Daniel> I believe this was due to an off-by-one error fixed in
Daniel> commit 9219.
Since I only saw your fix after I fixed the problem for myself and I
would have to roll back everything to see if it works, I would like to
suggest to add the following diff to
mythtv/libs/libmythtv/mpeg/dvbdescriptors.cpp.
This adds some checks to the dvb_decode_text function that would avoid
segfaults. To see that there might be trouble in other function some
warning messages could be added instead of just returning N/A.
Marcus
Index: dvbdescriptors.cpp
===================================================================
--- dvbdescriptors.cpp (revision 9218)
+++ dvbdescriptors.cpp (working copy)
@@ -12,16 +12,21 @@
if (!length)
return QString("");
- unsigned char buf[length];
+ unsigned char buf[length+1];
+ memset(buf, 0, length+1);
memcpy(buf, src, length);
if ((buf[0] <= 0x10) || (buf[0] >= 0x20))
{
// Strip formatting characters
for (uint p = 0; p < length; p++)
- {
- if ((buf[p] >= 0x80) && (buf[p] <= 0x9F))
- memmove(buf + p, buf + p + 1, --length - p);
+ {
+ if ((buf[p] >= 0x80) && (buf[p] <= 0x9F)){
+ if (p < length - 1){
+ memmove(buf + p, buf + p + 1, --length - p);
+ }
+ length--;
+ }
}
if (buf[0] >= 0x20)
@@ -30,9 +35,12 @@
}
else if ((buf[0] >= 0x01) && (buf[0] <= 0x0B))
{
- QString coding = "ISO8859-" + QString::number(4 + buf[0]);
+ QString coding = "ISO8859-" + QString::number(4 + int(buf[0]));
QTextCodec *codec = QTextCodec::codecForName(coding);
- result = codec->toUnicode((const char*)buf + 1, length - 1);
+ if (codec && length > 1)
+ result = codec->toUnicode((const char*)buf + 1, length - 1);
+ else
+ result = "N/A";
}
else if (buf[0] == 0x10)
{
@@ -41,17 +49,26 @@
// to indicate that the remaining data of the text field is
// coded using the character code table specified by
// ISO Standard 8859, parts 1 to 9
+ uint code = 1;
+ uint16_t co=0;
- uint code = 1;
- swab(buf + 1, &code, 2);
- QString coding = "ISO8859-" + QString::number(code);
- QTextCodec *codec = QTextCodec::codecForName(coding);
- result = codec->toUnicode((const char*)buf + 3, length - 3);
+ co = buf[0] << 8 | buf[1];
+ code = uint(co);
+ QString coding = "ISO8859-" + QString::number(code);
+ QTextCodec *codec = QTextCodec::codecForName(coding);
+ if (codec && length > 3){
+ result = codec->toUnicode((const char*)buf + 3, length - 3);
+ } else {
+ result = "N/A";
+ }
}
else
{
// Unknown/invalid encoding - assume local8Bit
- result = QString::fromLocal8Bit((const char*)buf + 1, length - 1);
+ if (length > 1)
+ result = QString::fromLocal8Bit((const char*)buf + 1, length - 1);
+ else
+ result = "N/A";
}
}
else
@@ -62,7 +79,6 @@
"Multi-byte coded text - not supported!");
result = "N/A";
}
-
return result;
}
--
/--------------------------------------------------------------------\
| Dr. Marcus O.C. Metzler | |
| mocm at metzlerbros.de | http://www.metzlerbros.de/ |
\--------------------------------------------------------------------/
|>>> Quis custodiet ipsos custodes <<<|
More information about the mythtv-dev
mailing list