mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-03 09:01:50 -05:00
enforce maximum sample size in sample cache
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@787 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
cdba0527a8
commit
e1ac42dd10
4 changed files with 11 additions and 6 deletions
|
|
@ -133,6 +133,9 @@ int pa_scache_add_item(pa_core *c, const char *name, const pa_sample_spec *ss, c
|
||||||
pa_scache_entry *e;
|
pa_scache_entry *e;
|
||||||
assert(c && name);
|
assert(c && name);
|
||||||
|
|
||||||
|
if (chunk->length > PA_SCACHE_ENTRY_SIZE_MAX)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (!(e = scache_add_item(c, name)))
|
if (!(e = scache_add_item(c, name)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
#include <polypcore/memchunk.h>
|
#include <polypcore/memchunk.h>
|
||||||
#include <polypcore/sink.h>
|
#include <polypcore/sink.h>
|
||||||
|
|
||||||
|
#define PA_SCACHE_ENTRY_SIZE_MAX (1024*1024*2)
|
||||||
|
|
||||||
typedef struct pa_scache_entry {
|
typedef struct pa_scache_entry {
|
||||||
pa_core *core;
|
pa_core *core;
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@
|
||||||
#include <polypcore/queue.h>
|
#include <polypcore/queue.h>
|
||||||
#include <polypcore/xmalloc.h>
|
#include <polypcore/xmalloc.h>
|
||||||
#include <polypcore/log.h>
|
#include <polypcore/log.h>
|
||||||
|
#include <polypcore/core-scache.h>
|
||||||
|
|
||||||
#include "pstream.h"
|
#include "pstream.h"
|
||||||
|
|
||||||
|
|
@ -52,7 +53,7 @@ enum {
|
||||||
typedef uint32_t pa_pstream_descriptor[PA_PSTREAM_DESCRIPTOR_MAX];
|
typedef uint32_t pa_pstream_descriptor[PA_PSTREAM_DESCRIPTOR_MAX];
|
||||||
|
|
||||||
#define PA_PSTREAM_DESCRIPTOR_SIZE (PA_PSTREAM_DESCRIPTOR_MAX*sizeof(uint32_t))
|
#define PA_PSTREAM_DESCRIPTOR_SIZE (PA_PSTREAM_DESCRIPTOR_MAX*sizeof(uint32_t))
|
||||||
#define FRAME_SIZE_MAX (1024*500) /* half a megabyte */
|
#define FRAME_SIZE_MAX PA_SCACHE_ENTRY_SIZE_MAX /* allow uploading a single sample in one frame at max */
|
||||||
|
|
||||||
struct item_info {
|
struct item_info {
|
||||||
enum { PA_PSTREAM_ITEM_PACKET, PA_PSTREAM_ITEM_MEMBLOCK } type;
|
enum { PA_PSTREAM_ITEM_PACKET, PA_PSTREAM_ITEM_MEMBLOCK } type;
|
||||||
|
|
@ -419,7 +420,7 @@ static int do_read(pa_pstream *p) {
|
||||||
|
|
||||||
/* Frame size too large */
|
/* Frame size too large */
|
||||||
if (ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]) > FRAME_SIZE_MAX) {
|
if (ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]) > FRAME_SIZE_MAX) {
|
||||||
pa_log_warn(__FILE__": Frame size too large");
|
pa_log_warn(__FILE__": Frame size too large: %lu > %lu", (unsigned long) ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]), (unsigned long) FRAME_SIZE_MAX);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,7 @@
|
||||||
#include <polypcore/log.h>
|
#include <polypcore/log.h>
|
||||||
|
|
||||||
#include "sound-file.h"
|
#include "sound-file.h"
|
||||||
|
#include "core-scache.h"
|
||||||
#define MAX_FILE_SIZE (1024*1024)
|
|
||||||
|
|
||||||
int pa_sound_file_load(const char *fname, pa_sample_spec *ss, pa_channel_map *map, pa_memchunk *chunk, pa_memblock_stat *s) {
|
int pa_sound_file_load(const char *fname, pa_sample_spec *ss, pa_channel_map *map, pa_memchunk *chunk, pa_memblock_stat *s) {
|
||||||
SNDFILE*sf = NULL;
|
SNDFILE*sf = NULL;
|
||||||
|
|
@ -78,7 +77,7 @@ int pa_sound_file_load(const char *fname, pa_sample_spec *ss, pa_channel_map *ma
|
||||||
if (map)
|
if (map)
|
||||||
pa_channel_map_init_auto(map, ss->channels);
|
pa_channel_map_init_auto(map, ss->channels);
|
||||||
|
|
||||||
if ((l = pa_frame_size(ss)*sfinfo.frames) > MAX_FILE_SIZE) {
|
if ((l = pa_frame_size(ss)*sfinfo.frames) > PA_SCACHE_ENTRY_SIZE_MAX) {
|
||||||
pa_log(__FILE__": File too large");
|
pa_log(__FILE__": File too large");
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +133,7 @@ int pa_sound_file_too_big_to_cache(const char *fname) {
|
||||||
ss.rate = sfinfo.samplerate;
|
ss.rate = sfinfo.samplerate;
|
||||||
ss.channels = sfinfo.channels;
|
ss.channels = sfinfo.channels;
|
||||||
|
|
||||||
if ((pa_frame_size(&ss) * sfinfo.frames) > MAX_FILE_SIZE) {
|
if ((pa_frame_size(&ss) * sfinfo.frames) > PA_SCACHE_ENTRY_SIZE_MAX) {
|
||||||
pa_log(__FILE__": File too large %s", fname);
|
pa_log(__FILE__": File too large %s", fname);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue