eitd: fix content classification bug introduced in 6eb8fa1c9e3a70a1e60465b838fe954c51e478b6

Origin commit data
------------------
Commit: c5ab2b994f
Author: martii <m4rtii@gmx.de>
Date: 2014-09-22 (Mon, 22 Sep 2014)
This commit is contained in:
martii
2014-09-22 22:24:42 +02:00
committed by [CST] Focus
parent aaad1652e8
commit eef29f8fbf
2 changed files with 52 additions and 39 deletions

View File

@@ -234,11 +234,13 @@ void SIevent::parse(Event &event)
{
const ContentDescriptor * d = (ContentDescriptor *) *dit;
const ContentClassificationList *clist = d->getClassifications();
ssize_t off = classifications.reserve(clist->size() * 2);
for (ContentClassificationConstIterator cit = clist->begin(); cit != clist->end(); ++cit)
off = classifications.set(off,
(*cit)->getContentNibbleLevel1() << 4 | (*cit)->getContentNibbleLevel2(),
(*cit)->getUserNibble1() << 4 | (*cit)->getUserNibble2());
if (clist->size()) {
ssize_t off = classifications.reserve(clist->size() * 2);
for (ContentClassificationConstIterator cit = clist->begin(); cit != clist->end(); ++cit)
off = classifications.set(off,
(*cit)->getContentNibbleLevel1() << 4 | (*cit)->getContentNibbleLevel2(),
(*cit)->getUserNibble1() << 4 | (*cit)->getUserNibble2());
}
break;
}
case COMPONENT_DESCRIPTOR:
@@ -301,21 +303,21 @@ void SIevent::parseDescriptors(const uint8_t *des, unsigned len)
while(len>=sizeof(struct descr_generic_header)) {
desc=(struct descr_generic_header *)des;
/*printf("Type: %s\n", decode_descr(desc->descriptor_tag)); */
if(desc->descriptor_tag==0x4D)
if(desc->descriptor_tag==SHORT_EVENT_DESCRIPTOR)
parseShortEventDescriptor((const uint8_t *)desc, len);
else if(desc->descriptor_tag==0x4E)
else if(desc->descriptor_tag==EXTENDED_EVENT_DESCRIPTOR)
parseExtendedEventDescriptor((const uint8_t *)desc, len);
else if(desc->descriptor_tag==0x54)
else if(desc->descriptor_tag==CONTENT_DESCRIPTOR)
parseContentDescriptor((const uint8_t *)desc, len);
else if(desc->descriptor_tag==0x50)
else if(desc->descriptor_tag==COMPONENT_DESCRIPTOR)
parseComponentDescriptor((const uint8_t *)desc, len);
else if(desc->descriptor_tag==0x55)
else if(desc->descriptor_tag==PARENTAL_RATING_DESCRIPTOR)
parseParentalRatingDescriptor((const uint8_t *)desc, len);
else if(desc->descriptor_tag==0x4A) {
else if(desc->descriptor_tag==LINKAGE_DESCRIPTOR) {
parseLinkageDescriptor((const uint8_t *)desc, len);
}
#if 0
else if(desc->descriptor_tag==0x69)
else if(desc->descriptor_tag==PDC_DESCRIPTOR)
parsePDCDescriptor((const char *)desc, e, len);
#endif
if((unsigned)(desc->descriptor_length+2)>len)
@@ -397,6 +399,8 @@ void SIevent::parseContentDescriptor(const uint8_t *buf, unsigned maxlen)
struct descr_generic_header *cont=(struct descr_generic_header *)buf;
if(cont->descriptor_length+sizeof(struct descr_generic_header)>maxlen)
return;
if(!cont->descriptor_length)
return;
ssize_t off = classifications.reserve(cont->descriptor_length);
classifications.set(off, buf + sizeof(struct descr_generic_header), cont->descriptor_length);
}

View File

@@ -382,14 +382,18 @@ class SIevent
SIeventClassifications& operator = (const SIeventClassifications& c)
{
if (this != &c) {
if (data)
size = 0;
if (data) {
free(data);
data = NULL;
}
if (c.data) {
data = (uint8_t *) malloc(c.size);
memcpy(data, c.data, c.size);
} else
data = NULL;
size = c.size;
if (data) {
memcpy(data, c.data, c.size);
size = c.size;
}
}
}
return *this;
}
@@ -397,12 +401,8 @@ class SIevent
SIeventClassifications(const SIeventClassifications& c)
{
if (this != &c) {
if (c.data) {
data = (uint8_t *) malloc(c.size);
memcpy(data, c.data, c.size);
} else
data = NULL;
size = c.size;
data = NULL;
*this = c;
}
}
@@ -419,7 +419,7 @@ class SIevent
bool operator!=(const SIeventClassifications& c) const
{
return *this == c;
return *this != c;
}
SIeventClassifications()
@@ -430,52 +430,61 @@ class SIevent
~SIeventClassifications()
{
if (data) free(data);
if (data)
free(data);
}
void get(std::string &contentClassifications, std::string &userClassifications) const
{
contentClassifications.clear();
userClassifications.clear();
uint8_t *d = data;
unsigned int z = size & ~1;
for (unsigned int i = 0; i < z; i += 2) {
contentClassifications.append(1, (char)(*d++));
userClassifications.append(1, (char)(*d++));
if (size) {
uint8_t *d = data, *e = data + size;
uint8_t cc[size/2], uc[size/2];
for (unsigned int i = 0; d < e; i++) {
cc[i] = *d++;
uc[i] = *d++;
}
contentClassifications.assign((char *) cc, size/2);
userClassifications.assign((char *) uc, size/2);
}
}
ssize_t reserve(unsigned int r)
{
size_t off = size;
if (r & 1)
return -1;
if (off) {
if (size) {
uint8_t * _data = (uint8_t *) realloc(data, size + r);
if (!_data)
return -1;
data = _data;
} else
} else {
data = (uint8_t *) malloc(r);
if (!data)
return -1;
}
size_t off = size;
size += r;
return off;
}
ssize_t set(ssize_t off, uint8_t content, uint8_t user)
{
if (off < -1 || off + 2 >= (ssize_t) size)
if (off < 0 || off + 2 > (ssize_t) size)
return -1;
data[off++] = content;
data[off++] = user;
return off;
}
ssize_t set(ssize_t off, const uint8_t *_data, size_t _size)
ssize_t set(ssize_t off, const uint8_t *_data, size_t len)
{
if (off < -1 || off + _size >= size)
if (len & 1 || off < 0 || off + len > size)
return -1;
memcpy (data + off, _data, _size);
size += _size;
return size;
memcpy (data + off, _data, len);
return off + len;
}
};