|
|
@@ -3,16 +3,18 @@
|
|
|
* implements the properties in the browser's documented subset. */
|
|
|
|
|
|
#include "browser_html.h"
|
|
|
+#include <stdlib.h>
|
|
|
#include <string.h>
|
|
|
|
|
|
static int is_space(char c);
|
|
|
static int is_ident(char c);
|
|
|
|
|
|
-/* ---- storage (one document per process) ---- */
|
|
|
-
|
|
|
-static struct br_node nodes_store[BR_MAX_NODES];
|
|
|
-static char text_store[BR_TEXT_SIZE];
|
|
|
-static char attr_store[BR_ATTR_SIZE];
|
|
|
+/* ---- storage (one document per process) ----
|
|
|
+ *
|
|
|
+ * The node/text/attribute arenas are allocated from the ring-3 heap, not
|
|
|
+ * static BSS: a large article needs several MB and the process image lives
|
|
|
+ * in the 4 MB user window. heap_reset() on navigation releases them with
|
|
|
+ * the rest of the page heap. */
|
|
|
static struct br_rule rule_fallback[BR_RULE_FALLBACK];
|
|
|
static char css_store[BR_CSS_SIZE];
|
|
|
static int root_font_px = 16;
|
|
|
@@ -791,9 +793,18 @@ void br_doc_init(struct br_doc *d)
|
|
|
for (i = 0; i < sizeof(*d); i++)
|
|
|
((unsigned char *)d)[i] = 0;
|
|
|
rule_index_reset(d);
|
|
|
- d->nodes = nodes_store;
|
|
|
- d->text = text_store;
|
|
|
- d->attrs = attr_store;
|
|
|
+ d->nodes = malloc(BR_MAX_NODES * sizeof(*d->nodes));
|
|
|
+ d->text = malloc(BR_TEXT_SIZE);
|
|
|
+ d->attrs = malloc(BR_ATTR_SIZE);
|
|
|
+ if (!d->nodes || !d->text || !d->attrs) {
|
|
|
+ free(d->nodes);
|
|
|
+ free(d->text);
|
|
|
+ free(d->attrs);
|
|
|
+ d->nodes = 0;
|
|
|
+ d->text = 0;
|
|
|
+ d->attrs = 0;
|
|
|
+ return;
|
|
|
+ }
|
|
|
d->rules = rule_fallback;
|
|
|
d->rule_cap = BR_RULE_FALLBACK;
|
|
|
d->attrs_used = 1; /* offset 0 = "no attribute" */
|
|
|
@@ -4205,9 +4216,16 @@ static void add_font_shorthand(struct br_decl *out, unsigned int *nout,
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
- if (!parse_font_size(v + ts, slash < tl ? slash : tl,
|
|
|
- &size_raw, &size_unit))
|
|
|
- continue;
|
|
|
+ {
|
|
|
+ unsigned short raw;
|
|
|
+ unsigned char unit;
|
|
|
+
|
|
|
+ if (!parse_font_size(v + ts, slash < tl ? slash : tl,
|
|
|
+ &raw, &unit))
|
|
|
+ continue;
|
|
|
+ size_raw = raw;
|
|
|
+ size_unit = unit;
|
|
|
+ }
|
|
|
have_size = 1;
|
|
|
if (slash < tl) {
|
|
|
unsigned int lstart = ts + slash + 1;
|
|
|
@@ -7096,6 +7114,8 @@ int br_parse(struct br_doc *d, const char *html, unsigned int len)
|
|
|
return -1;
|
|
|
if (!d->nodes)
|
|
|
br_doc_init(d);
|
|
|
+ if (!d->nodes || !d->text || !d->attrs)
|
|
|
+ return -1;
|
|
|
doc_reset(d);
|
|
|
d->script_src = html;
|
|
|
stack[0] = 0;
|
|
|
@@ -7369,6 +7389,8 @@ int br_parse_plain(struct br_doc *d, const char *text, unsigned int len)
|
|
|
{
|
|
|
if (!d->nodes)
|
|
|
br_doc_init(d);
|
|
|
+ if (!d->nodes || !d->text || !d->attrs)
|
|
|
+ return -1;
|
|
|
doc_reset(d);
|
|
|
d->plain = 1;
|
|
|
d->nodes[0].type = BR_NODE_ELEM;
|
|
|
@@ -7386,6 +7408,8 @@ unsigned int br_parse_image_doc(struct br_doc *d, const char *src)
|
|
|
|
|
|
if (!d->nodes)
|
|
|
br_doc_init(d);
|
|
|
+ if (!d->nodes || !d->text || !d->attrs)
|
|
|
+ return 0;
|
|
|
doc_reset(d);
|
|
|
d->nodes[0].type = BR_NODE_ELEM;
|
|
|
d->nodes[0].tag = BR_TAG_UNKNOWN;
|