from __future__ import absolute_import, division, unicode_literals
from six import text_type
-try:
- from functools import reduce
-except ImportError:
- pass
+import re
from ..constants import voidElements, booleanAttributes, spaceCharacters
from ..constants import rcdataElements, entities, xmlEntities
spaceCharacters = "".join(spaceCharacters)
+quoteAttributeSpecChars = spaceCharacters + "\"'=<>`"
+quoteAttributeSpec = re.compile("[" + quoteAttributeSpecChars + "]")
+quoteAttributeLegacy = re.compile("[" + quoteAttributeSpecChars +
+ "\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n"
+ "\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15"
+ "\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
+ "\x20\x2f\x60\xa0\u1680\u180e\u180f\u2000"
+ "\u2001\u2002\u2003\u2004\u2005\u2006\u2007"
+ "\u2008\u2009\u200a\u2028\u2029\u202f\u205f"
+ "\u3000]")
+
try:
from codecs import register_error, xmlcharrefreplace_errors
except ImportError:
class HTMLSerializer(object):
# attribute quoting options
- quote_attr_values = False
+ quote_attr_values = "legacy" # be secure by default
quote_char = '"'
use_best_quote_char = True
inject_meta_charset=True|False
Whether it insert a meta element to define the character set of the
document.
- quote_attr_values=True|False
+ quote_attr_values="legacy"|"spec"|"always"
Whether to quote attribute values that don't require quoting
- per HTML5 parsing rules.
+ per legacy browser behaviour, when required by the standard, or always.
quote_char=u'"'|u"'"
Use given quote character for attribute quoting. Default is to
use double quote unless attribute value contains a double quote,
yield self.encodeStrict(k)
if not self.minimize_boolean_attributes or \
- (k not in booleanAttributes.get(name, tuple())
- and k not in booleanAttributes.get("", tuple())):
+ (k not in booleanAttributes.get(name, tuple()) and
+ k not in booleanAttributes.get("", tuple())):
yield self.encodeStrict("=")
- if self.quote_attr_values or not v:
+ if self.quote_attr_values == "always" or len(v) == 0:
quote_attr = True
+ elif self.quote_attr_values == "spec":
+ quote_attr = quoteAttributeSpec.search(v) is not None
+ elif self.quote_attr_values == "legacy":
+ quote_attr = quoteAttributeLegacy.search(v) is not None
else:
- quote_attr = reduce(lambda x, y: x or (y in v),
- spaceCharacters + ">\"'=", False)
+ raise ValueError("quote_attr_values must be one of: "
+ "'always', 'spec', or 'legacy'")
v = v.replace("&", "&")
if self.escape_lt_in_attrs:
v = v.replace("<", "<")
s->tile_offset_x = bytestream2_get_be32u(&s->g); // XT0Siz
s->tile_offset_y = bytestream2_get_be32u(&s->g); // YT0Siz
ncomponents = bytestream2_get_be16u(&s->g); // CSiz
+ if (s->image_offset_x || s->image_offset_y) {
+ avpriv_request_sample(s->avctx, "Support for image offsets");
+ return AVERROR_PATCHWELCOME;
+ }
if (av_image_check_size2(s->width, s->height, s->avctx->max_pixels, AV_PIX_FMT_NONE, 0, s->avctx)) {
avpriv_request_sample(s->avctx, "Large Dimensions");
av_log(s->avctx, AV_LOG_ERROR, "cblk size invalid\n");
return AVERROR_INVALIDDATA;
}
-
+ if (c->log2_cblk_width > 6 || c->log2_cblk_height > 6) {
+ avpriv_request_sample(s->avctx, "cblk size > 64");
+ return AVERROR_PATCHWELCOME;
+ }
c->cblk_style = bytestream2_get_byteu(&s->g);
if (c->cblk_style != 0) { // cblk style
if (c->cblk_style & JPEG2000_CTSY_HTJ2K_M || c->cblk_style & JPEG2000_CTSY_HTJ2K_F) {
int vert_causal_ctx_csty_symbol = codsty->cblk_style & JPEG2000_CBLK_VSC;
int term_cnt = 0;
int coder_type;
-
+ av_assert0(width <= JPEG2000_MAX_CBLKW);
+ av_assert0(height <= JPEG2000_MAX_CBLKH);
av_assert0(width <= 1024U && height <= 1024U);
av_assert0(width*height <= 4096);
uint16_t *pixels;
int row_ptr = 0;
- int pixel_ptr = 0;
+ int pixel_ptr = -4;
int block_ptr;
int pixel_x, pixel_y;
int total_blocks;
colorA = bytestream2_get_be16(&s->gb);
while (n_blocks--) {
CHECK_BLOCK();
+ ADVANCE_BLOCK();
block_ptr = row_ptr + pixel_ptr;
for (pixel_y = 0; pixel_y < 4; pixel_y++) {
for (pixel_x = 0; pixel_x < 4; pixel_x++){
}
block_ptr += row_inc;
}
- ADVANCE_BLOCK();
}
break;
return AVERROR_INVALIDDATA;
while (n_blocks--) {
CHECK_BLOCK();
+ ADVANCE_BLOCK();
block_ptr = row_ptr + pixel_ptr;
for (pixel_y = 0; pixel_y < 4; pixel_y++) {
uint8_t index = bytestream2_get_byteu(&s->gb);
}
block_ptr += row_inc;
}
- ADVANCE_BLOCK();
}
break;
if (bytestream2_get_bytes_left(&s->gb) < 30)
return AVERROR_INVALIDDATA;
CHECK_BLOCK();
+ ADVANCE_BLOCK();
block_ptr = row_ptr + pixel_ptr;
for (pixel_y = 0; pixel_y < 4; pixel_y++) {
for (pixel_x = 0; pixel_x < 4; pixel_x++){
}
block_ptr += row_inc;
}
- ADVANCE_BLOCK();
break;
/* Unknown opcode */
{
}
+/* Dummy postprocessing function used by jpeg_skip_scanlines() */
+LOCAL(void)
+noop_post_process (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
+ JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
+ JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
+{
+}
/*
* In some cases, it is best to call jpeg_read_scanlines() and discard the
int num_rows) = NULL;
void (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) = NULL;
-
+ void (*post_process_data) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
+ JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail) = NULL;
if (cinfo->cconvert && cinfo->cconvert->color_convert) {
color_convert = cinfo->cconvert->color_convert;
cinfo->cconvert->color_convert = noop_convert;
}
#ifdef UPSAMPLE_MERGING_SUPPORTED
+ if (master->using_merged_upsample && cinfo->post &&
+ cinfo->post->post_process_data) {
+ post_process_data = cinfo->post->post_process_data;
+ cinfo->post->post_process_data = noop_post_process;
+ }
if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
scanlines = &upsample->spare_row;
if (color_quantize)
cinfo->cquantize->color_quantize = color_quantize;
+
+ if (post_process_data)
+ cinfo->post->post_process_data = post_process_data;
}
my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
my_master_ptr master = (my_master_ptr)cinfo->master;
- my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
JDIMENSION i, x;
int y;
JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
main_ptr->buffer_full = FALSE;
main_ptr->rowgroup_ctr = 0;
main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
- if (!master->using_merged_upsample) {
+ if (master->using_merged_upsample) {
+ my_merged_upsample_ptr upsample =
+ (my_merged_upsample_ptr)cinfo->upsample;
+ upsample->spare_full = FALSE;
+ upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
+ } else {
+ my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
upsample->next_row_out = cinfo->max_v_samp_factor;
upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
}
cinfo->output_scanline += lines_left_in_iMCU_row;
main_ptr->buffer_full = FALSE;
main_ptr->rowgroup_ctr = 0;
- if (!master->using_merged_upsample) {
+ if (master->using_merged_upsample) {
+ my_merged_upsample_ptr upsample =
+ (my_merged_upsample_ptr)cinfo->upsample;
+ upsample->spare_full = FALSE;
+ upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
+ } else {
+ my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
upsample->next_row_out = cinfo->max_v_samp_factor;
upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
}
cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
increment_simple_rowgroup_ctr(cinfo, lines_to_read);
}
- if (!master->using_merged_upsample)
+ if (master->using_merged_upsample) {
+ my_merged_upsample_ptr upsample =
+ (my_merged_upsample_ptr)cinfo->upsample;
+ upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
+ } else {
+ my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
+ }
return num_lines;
}
* bit odd, since "rows_to_go" seems to be redundantly keeping track of
* output_scanline.
*/
- if (!master->using_merged_upsample)
+ if (master->using_merged_upsample) {
+ my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
+ upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
+ } else {
+ my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
+ }
/* Always skip the requested number of lines. */
return num_lines;