From patchwork Wed Jan 8 22:12:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Roth?= X-Patchwork-Id: 3456161 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 037929F1C4 for ; Wed, 8 Jan 2014 22:13:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2DC132016D for ; Wed, 8 Jan 2014 22:13:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4CDC92015F for ; Wed, 8 Jan 2014 22:13:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932527AbaAHWNL (ORCPT ); Wed, 8 Jan 2014 17:13:11 -0500 Received: from mail-ea0-f177.google.com ([209.85.215.177]:40189 "EHLO mail-ea0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932523AbaAHWNJ (ORCPT ); Wed, 8 Jan 2014 17:13:09 -0500 Received: by mail-ea0-f177.google.com with SMTP id n15so1090067ead.8 for ; Wed, 08 Jan 2014 14:13:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=KBQ0KIxUoqCA5iDjmd6g/906m3vK/swjDkSiI2AV2wc=; b=OyacRuoIgn2PwJNYavPr5LqW+xfN7u5M5HxHkI3mptlHm/h9CbQ4o++5mgh6LgqpmP S/QAW94L8mobWqhxBk9Xo752ufp66xlEU7yIcGxxNrLGG2h9MeWsWsX90L6G82zg7GLF 7g1M6sjQV03kzy1RBGlN6nlz/WuLYMkua6UehqmcSRxrA/mhMWNln8z+IhQ7dSHOoxA+ 9hgLD8SnLYMxIfIVojmYWJYYhJ8tGjPILtJF/GbPU+786qEnWoM5cYDnlILcxw6dSAcP 0aNM1K1mIlqEgQthEU06fkmtz5jBYp1xGHS/RrncGbmfx+gMg5PuLnB8EpVivaXNer8B FUZQ== X-Received: by 10.15.44.4 with SMTP id y4mr28567792eev.71.1389219187169; Wed, 08 Jan 2014 14:13:07 -0800 (PST) Received: from neutrino.exnihilo (140-227.61-188.cust.bluewin.ch. [188.61.227.140]) by mx.google.com with ESMTPSA id e3sm193265067eeg.11.2014.01.08.14.13.06 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 14:13:06 -0800 (PST) From: =?UTF-8?q?Andr=C3=A9=20Roth?= To: linux-media@vger.kernel.org Cc: =?UTF-8?q?Andr=C3=A9=20Roth?= Subject: [PATCH 1/2] libdvbv5: fix reading multisection tables Date: Wed, 8 Jan 2014 23:12:46 +0100 Message-Id: <1389219167-23293-1-git-send-email-neolynx@gmail.com> X-Mailer: git-send-email 1.8.3.2 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Unfortunately the section ids are not granted to be incremented by one. This means the last section id is not necessarily equal to the total number of sections. The only way to know if everything has been parsed, is to stop when a repeating section id has been found. The sections do not need to contain the same table id. In EIT for example, the id designates the corresponding service. Thus, allow the table id to differ. Signed-off-by: André Roth --- lib/libdvbv5/dvb-scan.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/libdvbv5/dvb-scan.c b/lib/libdvbv5/dvb-scan.c index e69d852..95219fa 100644 --- a/lib/libdvbv5/dvb-scan.c +++ b/lib/libdvbv5/dvb-scan.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2011-2012 - Mauro Carvalho Chehab + * Copyright (c) 2013 - Andre Roth * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -97,9 +98,12 @@ int dvb_read_section_with_id(struct dvb_v5_fe_parms *parms, int dmx_fd, uint8_t *buf = NULL; uint8_t *tbl = NULL; ssize_t table_length = 0; + + /* variables for section handling */ + int start_id = -1; + int start_section = -1; int first_section = -1; int last_section = -1; - int table_id = -1; int sections = 0; struct dmx_sct_filter_params f; struct dvb_table_header *h; @@ -186,24 +190,25 @@ int dvb_read_section_with_id(struct dvb_v5_fe_parms *parms, int dmx_fd, h = (struct dvb_table_header *)buf; dvb_table_header_init(h); + + if (start_id == h->id && start_section == h->section_id) { + dvb_logdbg( "dvb_read_section: section repeated, reading done" ); + break; + } + if (start_id == -1) start_id = h->id; + if (start_section == -1) start_section = h->section_id; + if (id != -1 && h->id != id) { /* search for a specific table id */ continue; - } else { - if (table_id == -1) - table_id = h->id; - else if (h->id != table_id) { - dvb_logwarn("dvb_read_section: table ID mismatch reading multi section table: %d != %d", h->id, table_id); - continue; - } } /* handle the sections */ if (first_section == -1) first_section = h->section_id; - else if (h->section_id == first_section) + else if (start_id == h->id && h->section_id == first_section) break; - if (last_section == -1) + if (last_section == -1 || h->last_section > last_section) last_section = h->last_section; if (!tbl) { @@ -229,8 +234,10 @@ int dvb_read_section_with_id(struct dvb_v5_fe_parms *parms, int dmx_fd, else dvb_logerr("dvb_read_section: no initializer for table %d", tid); - if (++sections == last_section + 1) + if (id != -1 && ++sections == last_section + 1) { + dvb_logerr("dvb_read_section: read more sections than last section id: %d / %d", sections, last_section); break; + } } free(buf);