libs/gst/base/gsttypefindhelper.c: Fix off-by-one bug that would only allow peeks of N-1 bytes from the start even if...

Original commit message from CVS:
* libs/gst/base/gsttypefindhelper.c: (buf_helper_find_peek):
Fix off-by-one bug that would only allow peeks of N-1 bytes
from the start even if the buffer to typefind on contains
in fact N bytes of data (makes vorbis typefinding from a
vorbis identification header buffer work).
* tests/check/Makefile.am:
* tests/check/libs/.cvsignore:
* tests/check/libs/typefindhelper.c: (GST_START_TEST),
(gst_typefindhelper_suite), (main), (foobar_typefind),
(plugin_init):
Add very basic unit test for gst_type_find_helper_for_buffer()
that checks for the problem fixed above.
This commit is contained in:
Tim-Philipp Müller 2006-05-24 17:11:06 +00:00
parent 649045a64b
commit 651061dfd9
5 changed files with 172 additions and 1 deletions

View file

@ -1,3 +1,19 @@
2006-05-24 Tim-Philipp Müller <tim at centricular dot net>
* libs/gst/base/gsttypefindhelper.c: (buf_helper_find_peek):
Fix off-by-one bug that would only allow peeks of N-1 bytes
from the start even if the buffer to typefind on contains
in fact N bytes of data (makes vorbis typefinding from a
vorbis identification header buffer work).
* tests/check/Makefile.am:
* tests/check/libs/.cvsignore:
* tests/check/libs/typefindhelper.c: (GST_START_TEST),
(gst_typefindhelper_suite), (main), (foobar_typefind),
(plugin_init):
Add very basic unit test for gst_type_find_helper_for_buffer()
that checks for the problem fixed above.
2006-05-24 Thomas Vander Stichele <thomas at apestaart dot org> 2006-05-24 Thomas Vander Stichele <thomas at apestaart dot org>
* tools/gst-inspect.c: (print_interfaces), * tools/gst-inspect.c: (print_interfaces),

View file

@ -297,7 +297,7 @@ buf_helper_find_peek (gpointer data, gint64 off, guint size)
return NULL; return NULL;
} }
if ((off + size) < helper->size) if ((off + size) <= helper->size)
return helper->data + off; return helper->data + off;
return NULL; return NULL;

View file

@ -54,6 +54,7 @@ REGISTRY_CHECKS = \
elements/identity \ elements/identity \
libs/basesrc \ libs/basesrc \
libs/controller \ libs/controller \
libs/typefindhelper \
pipelines/stress pipelines/stress
endif endif
@ -117,6 +118,9 @@ libs_gstnetclientclock_LDADD = \
libs_gstnettimeprovider_LDADD = \ libs_gstnettimeprovider_LDADD = \
$(top_builddir)/libs/gst/net/libgstnet-@GST_MAJORMINOR@.la \ $(top_builddir)/libs/gst/net/libgstnet-@GST_MAJORMINOR@.la \
$(LDADD) $(LDADD)
libs_typefindhelper_LDADD = \
$(top_builddir)/libs/gst/base/libgstbase-@GST_MAJORMINOR@.la \
$(LDADD)
# valgrind testing # valgrind testing
# these just need valgrind fixing, period # these just need valgrind fixing, period

View file

@ -6,3 +6,4 @@ gstnetclientclock
gstnettimeprovider gstnettimeprovider
libsabi libsabi
basesrc basesrc
typefindhelper

View file

@ -0,0 +1,150 @@
/* GStreamer
*
* unit test for typefind helper
*
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/check/gstcheck.h>
#include <gst/base/gsttypefindhelper.h>
static const guint8 vorbisid[30] = { 0x01, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73,
0x00, 0x00, 0x00, 0x00, 0x02, 0x44, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xf4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x01
};
static GstStaticCaps foobar_caps = GST_STATIC_CAPS ("foo/x-bar");
#define FOOBAR_CAPS (gst_static_caps_get (&foobar_caps))
/* make sure the entire data in the buffer is available for peeking */
GST_START_TEST (test_buffer_range)
{
GstStructure *s;
GstBuffer *buf;
GstCaps *caps;
buf = gst_buffer_new ();
fail_unless (buf != NULL);
GST_BUFFER_DATA (buf) = (guint8 *) vorbisid;
GST_BUFFER_SIZE (buf) = 30;
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY);
caps = gst_type_find_helper_for_buffer (NULL, buf, NULL);
fail_unless (caps != NULL);
fail_unless (GST_CAPS_IS_SIMPLE (caps));
fail_unless (gst_caps_is_fixed (caps));
s = gst_caps_get_structure (caps, 0);
fail_unless (s != NULL);
fail_unless (gst_structure_has_name (s, "foo/x-bar"));
gst_caps_unref (caps);
gst_buffer_unref (buf);
}
GST_END_TEST;
Suite *
gst_typefindhelper_suite (void)
{
Suite *s = suite_create ("typefindhelper");
TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_buffer_range);
return s;
}
int
main (int argc, char **argv)
{
int nf;
Suite *s = gst_typefindhelper_suite ();
SRunner *sr = srunner_create (s);
gst_check_init (&argc, &argv);
srunner_run_all (sr, CK_NORMAL);
nf = srunner_ntests_failed (sr);
srunner_free (sr);
return nf;
}
static void
foobar_typefind (GstTypeFind * tf, gpointer unused)
{
guint8 *data;
data = gst_type_find_peek (tf, 0, 10);
fail_unless (data != NULL);
fail_unless (memcmp (data, vorbisid, 10) == 0);
data = gst_type_find_peek (tf, 0, 20);
fail_unless (data != NULL);
fail_unless (memcmp (data, vorbisid, 20) == 0);
data = gst_type_find_peek (tf, 0, 30);
fail_unless (data != NULL);
fail_unless (memcmp (data, vorbisid, 30) == 0);
fail_unless (gst_type_find_peek (tf, 0, 31) == NULL);
fail_unless (gst_type_find_peek (tf, 1, 30) == NULL);
fail_unless (gst_type_find_peek (tf, 25, 6) == NULL);
data = gst_type_find_peek (tf, 1, 29);
fail_unless (data != NULL);
fail_unless (memcmp (data, vorbisid + 1, 29) == 0);
data = gst_type_find_peek (tf, 25, 4);
fail_unless (data != NULL);
fail_unless (memcmp (data, vorbisid + 25, 4) == 0);
fail_unless (gst_type_find_peek (tf, -1, 29) == NULL);
fail_unless (gst_type_find_peek (tf, -1, 1) == NULL);
fail_unless (gst_type_find_peek (tf, -1, 0) == NULL);
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FOOBAR_CAPS);
}
static gboolean
plugin_init (GstPlugin * plugin)
{
static gchar *foobar_exts[] = { "foobar", NULL };
if (!gst_type_find_register (plugin, "foo/x-bar", GST_RANK_PRIMARY + 50,
foobar_typefind, foobar_exts, FOOBAR_CAPS, NULL, NULL)) {
return FALSE;
}
return TRUE;
}
GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"dummy typefind functions",
"dummy typefind functions",
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)