From gitlab at videolan.org Wed Jun 4 14:07:53 2025 From: gitlab at videolan.org (Christophe Massiot (@cmassiot)) Date: Wed, 04 Jun 2025 16:07:53 +0200 Subject: [bTSstream-devel] [Git][videolan/bitstream][master] 2 commits: Fix invalid XML characters Message-ID: <68405339a10d8_80c81b483f01148951d@gitlab.mail> Christophe Massiot pushed to branch master at VideoLAN / bitstream Commits: f123c9c0 by Cl?ment Vasseur at 2025-04-07T17:10:59+02:00 Fix invalid XML characters Make sure characters which are not valid UTF-8 or XML characters are properly replaced by the unicode replacement character. - - - - - 70d6a2fe by Christophe Massiot at 2025-06-04T16:07:45+02:00 Merge branch 'nto-xml-invalid-chars' - - - - - 1 changed file: - common.h Changes: ===================================== common.h ===================================== @@ -51,52 +51,86 @@ typedef enum print_type_t { typedef void (*f_print)(void *, const char *, ...) __attribute__ ((format(printf, 2, 3))); typedef char * (*f_iconv)(void *, const char *, char *, size_t); -static inline const char *bitstream_xml_escape_char(char c) +static inline size_t bitstream_xml_escape_chars(const char *str, char *out) { - switch (c) { - case '<': return "<"; - case '>': return ">"; - case '"': return """; - case '\'': return "'"; - case '&': return "&"; - } - return NULL; -} + size_t len = 1; + + while (*str) { + uint32_t codepoint = 0xFFFD; + const char *p = str; + int size = 1; + + unsigned char c = *str++; + if (c < 0x80) { + codepoint = c; + switch (c) { + case '<': p = "<"; size = 4; break; + case '>': p = ">"; size = 4; break; + case '"': p = """; size = 6; break; + case '\'': p = "'"; size = 6; break; + case '&': p = "&"; size = 5; break; + } + } else if ((c & 0xE0) == 0xC0) { + if ((str[0] & 0xC0) == 0x80) { + codepoint = ((c & 0x1F) << 6) | + (str[0] & 0x3F); + size = 2; + str += 1; + } + } else if ((c & 0xF0) == 0xE0) { + if ((str[0] & 0xC0) == 0x80 && + (str[1] & 0xC0) == 0x80) { + codepoint = ((c & 0x0F) << 12) | + ((str[0] & 0x3F) << 6) | + (str[1] & 0x3F); + size = 3; + str += 2; + } + } else if ((c & 0xF8) == 0xF0) { + if ((str[0] & 0xC0) == 0x80 && + (str[1] & 0xC0) == 0x80 && + (str[2] & 0xC0) == 0x80) { + codepoint = ((c & 0x07) << 18) | + ((str[0] & 0x3F) << 12) | + ((str[1] & 0x3F) << 6) | + (str[2] & 0x3F); + size = 4; + str += 3; + } + } -static inline size_t bitstream_xml_escape_len(const char *str) -{ - size_t len = str ? strlen(str) : 0; - size_t out_len = 0; - for (unsigned i = 0; i < len; i++) { - const char *esc = bitstream_xml_escape_char(str[i]); - out_len += esc ? strlen(esc) : 1; + // #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] + if (codepoint == 0xFFFD || + !(codepoint == 0x9 || + codepoint == 0xA || + codepoint == 0xD || + (codepoint >= 0x20 && codepoint <= 0xD7FF) || + (codepoint >= 0xE000 && codepoint <= 0xFFFD) || + (codepoint >= 0x10000 && codepoint <= 0x10FFFF))) { + p = "\uFFFD"; + size = 3; + } + + if (out) { + memcpy(out, p, size); + out += size; + } + len += size; } - return out_len; + + if (out) + *out = '\0'; + return len; } static inline char *bitstream_xml_escape(const char *str) { if (!str) return NULL; - - size_t len = strlen(str); - size_t out_len = bitstream_xml_escape_len(str); - char *out = (char *)malloc(out_len + 1); + char *out = (char *)malloc(bitstream_xml_escape_chars(str, NULL)); if (!out) return NULL; - - char *tmp = out; - for (unsigned i = 0; i < len; i++) { - const char *esc = bitstream_xml_escape_char(str[i]); - if (esc) { - size_t esc_len = strlen(esc); - memcpy(tmp, esc, esc_len); - tmp += esc_len; - } - else - *tmp++ = str[i]; - } - *tmp = '\0'; + bitstream_xml_escape_chars(str, out); return out; } View it on GitLab: https://code.videolan.org/videolan/bitstream/-/compare/fc71ca6d9da88e82ada96588ebf2e121cd3ad583...70d6a2fe5d53f46d69578531c1ba63bdd986b189 -- View it on GitLab: https://code.videolan.org/videolan/bitstream/-/compare/fc71ca6d9da88e82ada96588ebf2e121cd3ad583...70d6a2fe5d53f46d69578531c1ba63bdd986b189 You're receiving this email because of your account on code.videolan.org. VideoLAN code repository instance From gitlab at videolan.org Wed Jun 4 14:10:00 2025 From: gitlab at videolan.org (Christophe Massiot (@cmassiot)) Date: Wed, 04 Jun 2025 16:10:00 +0200 Subject: [bTSstream-devel] [Git][videolan/bitstream][master] 3 commits: mpeg/psi: Add J2K video descriptor Message-ID: <684053b8bff6a_80c817f2e1c114899b0@gitlab.mail> Christophe Massiot pushed to branch master at VideoLAN / bitstream Commits: 4967de92 by Peter Krefting at 2025-05-14T13:23:05+01:00 mpeg/psi: Add J2K video descriptor As defined in ITU-T H.222.0 - - - - - 1f619f74 by Cl?ment Vasseur at 2025-06-04T16:09:44+02:00 Fix invalid XML characters Make sure characters which are not valid UTF-8 or XML characters are properly replaced by the unicode replacement character. - - - - - 8b2bf575 by Christophe Massiot at 2025-06-04T16:09:51+02:00 Merge branch 'nafmo-J2K_descriptor' - - - - - 2 changed files: - + mpeg/psi/desc_32.h - mpeg/psi/descs_list.h Changes: ===================================== mpeg/psi/desc_32.h ===================================== @@ -0,0 +1,64 @@ +/***************************************************************************** + * desc_32.h: ISO/IEC 13818-1 Descriptor 0x32 (J2K video descriptor) + ***************************************************************************** + * Copyright Bridge Technologies Co AS + * + * Authors: Peter Krefting + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BITSTREAM_MPEG_DESC_32_H__ +#define __BITSTREAM_MPEG_DESC_32_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/***************************************************************************** + * Descriptor 0x32 (J2K video descriptor) + *****************************************************************************/ +#define DESC32_HEADER_SIZE (DESC_HEADER_SIZE + 24) + +static inline void desc32_init(uint8_t *p_desc) +{ + desc_set_tag(p_desc, 0x32); + desc_set_length(p_desc, DESC32_HEADER_SIZE - DESC_HEADER_SIZE); +} + +static inline bool desc32_validate(const uint8_t *p_desc) +{ + return desc_get_length(p_desc) >= DESC32_HEADER_SIZE - DESC_HEADER_SIZE; +} + +static inline bool desc32_get_interlaced_video(const uint8_t *p_desc) +{ + return (p_desc[25] & 0x01) == 0x01; +} + +#ifdef __cplusplus +} +#endif + +#endif ===================================== mpeg/psi/descs_list.h ===================================== @@ -69,6 +69,7 @@ #include #include #include +#include #include #include #include View it on GitLab: https://code.videolan.org/videolan/bitstream/-/compare/70d6a2fe5d53f46d69578531c1ba63bdd986b189...8b2bf575d593887e8fe58205d80c3948bb91a5bb -- View it on GitLab: https://code.videolan.org/videolan/bitstream/-/compare/70d6a2fe5d53f46d69578531c1ba63bdd986b189...8b2bf575d593887e8fe58205d80c3948bb91a5bb You're receiving this email because of your account on code.videolan.org. VideoLAN code repository instance