Mercurial > emacs
comparison src/coding.c @ 99753:c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
sequence.
(DECODE_COMPOSITION_START): If the current source is the last
block, and the current composition doesn't end, regard this
sequence as invalid.
(decode_coding_iso_2022): Handle invalid composition sequence.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Fri, 21 Nov 2008 02:23:06 +0000 |
| parents | 10cd979d05ca |
| children | 0e4115b39b5d |
comparison
equal
deleted
inserted
replaced
| 99752:25fea170fd1a | 99753:c457d1e5edff |
|---|---|
| 2756 int c, c1; | 2756 int c, c1; |
| 2757 int consumed_chars = 0; | 2757 int consumed_chars = 0; |
| 2758 int i; | 2758 int i; |
| 2759 int rejected = 0; | 2759 int rejected = 0; |
| 2760 int found = 0; | 2760 int found = 0; |
| 2761 int composition_count = -1; | |
| 2761 | 2762 |
| 2762 detect_info->checked |= CATEGORY_MASK_ISO; | 2763 detect_info->checked |= CATEGORY_MASK_ISO; |
| 2763 | 2764 |
| 2764 for (i = coding_category_iso_7; i <= coding_category_iso_8_else; i++) | 2765 for (i = coding_category_iso_7; i <= coding_category_iso_8_else; i++) |
| 2765 { | 2766 { |
| 2824 /* ESC <Fe> for SS2 or SS3. */ | 2825 /* ESC <Fe> for SS2 or SS3. */ |
| 2825 single_shifting = 1; | 2826 single_shifting = 1; |
| 2826 rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_8BIT; | 2827 rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_8BIT; |
| 2827 break; | 2828 break; |
| 2828 } | 2829 } |
| 2830 else if (c == '1') | |
| 2831 { | |
| 2832 /* End of composition. */ | |
| 2833 if (composition_count < 0 | |
| 2834 || composition_count > MAX_COMPOSITION_COMPONENTS) | |
| 2835 /* Invalid */ | |
| 2836 break; | |
| 2837 composition_count = -1; | |
| 2838 found |= CATEGORY_MASK_ISO; | |
| 2839 } | |
| 2829 else if (c >= '0' && c <= '4') | 2840 else if (c >= '0' && c <= '4') |
| 2830 { | 2841 { |
| 2831 /* ESC <Fp> for start/end composition. */ | 2842 /* ESC <Fp> for start/end composition. */ |
| 2832 found |= CATEGORY_MASK_ISO; | 2843 composition_count = 0; |
| 2833 break; | 2844 break; |
| 2834 } | 2845 } |
| 2835 else | 2846 else |
| 2836 { | 2847 { |
| 2837 /* Invalid escape sequence. Just ignore it. */ | 2848 /* Invalid escape sequence. Just ignore it. */ |
| 2898 default: | 2909 default: |
| 2899 if (c < 0) | 2910 if (c < 0) |
| 2900 continue; | 2911 continue; |
| 2901 if (c < 0x80) | 2912 if (c < 0x80) |
| 2902 { | 2913 { |
| 2914 if (composition_count >= 0) | |
| 2915 composition_count++; | |
| 2903 single_shifting = 0; | 2916 single_shifting = 0; |
| 2904 break; | 2917 break; |
| 2905 } | 2918 } |
| 2906 if (c >= 0xA0) | 2919 if (c >= 0xA0) |
| 2907 { | 2920 { |
| 2922 break; | 2935 break; |
| 2923 i++; | 2936 i++; |
| 2924 } | 2937 } |
| 2925 | 2938 |
| 2926 if (i & 1 && src < src_end) | 2939 if (i & 1 && src < src_end) |
| 2927 rejected |= CATEGORY_MASK_ISO_8_2; | 2940 { |
| 2941 rejected |= CATEGORY_MASK_ISO_8_2; | |
| 2942 if (composition_count >= 0) | |
| 2943 composition_count += i; | |
| 2944 } | |
| 2928 else | 2945 else |
| 2929 found |= CATEGORY_MASK_ISO_8_2; | 2946 { |
| 2947 found |= CATEGORY_MASK_ISO_8_2; | |
| 2948 if (composition_count >= 0) | |
| 2949 composition_count += i / 2; | |
| 2950 } | |
| 2930 } | 2951 } |
| 2931 break; | 2952 break; |
| 2932 } | 2953 } |
| 2933 check_extra_latin: | 2954 check_extra_latin: |
| 2934 single_shifting = 0; | 2955 single_shifting = 0; |
| 3041 for (p = src; p < src_end - 1; p++) \ | 3062 for (p = src; p < src_end - 1; p++) \ |
| 3042 if (*p == ISO_CODE_ESC && p[1] == '1') \ | 3063 if (*p == ISO_CODE_ESC && p[1] == '1') \ |
| 3043 break; \ | 3064 break; \ |
| 3044 if (p == src_end - 1) \ | 3065 if (p == src_end - 1) \ |
| 3045 { \ | 3066 { \ |
| 3067 if (coding->mode & CODING_MODE_LAST_BLOCK) \ | |
| 3068 goto invalid_code; \ | |
| 3046 /* The current composition doesn't end in the current \ | 3069 /* The current composition doesn't end in the current \ |
| 3047 source. */ \ | 3070 source. */ \ |
| 3048 record_conversion_result \ | 3071 record_conversion_result \ |
| 3049 (coding, CODING_RESULT_INSUFFICIENT_SRC); \ | 3072 (coding, CODING_RESULT_INSUFFICIENT_SRC); \ |
| 3050 goto no_more_source; \ | 3073 goto no_more_source; \ |
| 3188 if (composition_state != COMPOSING_NO) | 3211 if (composition_state != COMPOSING_NO) |
| 3189 { | 3212 { |
| 3190 if (composition_state == COMPOSING_RULE | 3213 if (composition_state == COMPOSING_RULE |
| 3191 || composition_state == COMPOSING_COMPONENT_RULE) | 3214 || composition_state == COMPOSING_COMPONENT_RULE) |
| 3192 { | 3215 { |
| 3193 DECODE_COMPOSITION_RULE (c1); | 3216 if (component_idx < MAX_COMPOSITION_COMPONENTS * 2 + 1) |
| 3194 components[component_idx++] = c1; | 3217 { |
| 3195 composition_state--; | 3218 DECODE_COMPOSITION_RULE (c1); |
| 3196 continue; | 3219 components[component_idx++] = c1; |
| 3220 composition_state--; | |
| 3221 continue; | |
| 3222 } | |
| 3223 /* Too long composition. */ | |
| 3224 MAYBE_FINISH_COMPOSITION (); | |
| 3197 } | 3225 } |
| 3198 } | 3226 } |
| 3199 if (charset_id_0 < 0 | 3227 if (charset_id_0 < 0 |
| 3200 || ! CHARSET_ISO_CHARS_96 (CHARSET_FROM_ID (charset_id_0))) | 3228 || ! CHARSET_ISO_CHARS_96 (CHARSET_FROM_ID (charset_id_0))) |
| 3201 /* This is SPACE or DEL. */ | 3229 /* This is SPACE or DEL. */ |
| 3208 if (composition_state != COMPOSING_NO) | 3236 if (composition_state != COMPOSING_NO) |
| 3209 { | 3237 { |
| 3210 if (composition_state == COMPOSING_RULE | 3238 if (composition_state == COMPOSING_RULE |
| 3211 || composition_state == COMPOSING_COMPONENT_RULE) | 3239 || composition_state == COMPOSING_COMPONENT_RULE) |
| 3212 { | 3240 { |
| 3213 DECODE_COMPOSITION_RULE (c1); | 3241 if (component_idx < MAX_COMPOSITION_COMPONENTS * 2 + 1) |
| 3214 components[component_idx++] = c1; | 3242 { |
| 3215 composition_state--; | 3243 DECODE_COMPOSITION_RULE (c1); |
| 3216 continue; | 3244 components[component_idx++] = c1; |
| 3245 composition_state--; | |
| 3246 continue; | |
| 3247 } | |
| 3248 MAYBE_FINISH_COMPOSITION (); | |
| 3217 } | 3249 } |
| 3218 } | 3250 } |
| 3219 if (charset_id_0 < 0) | 3251 if (charset_id_0 < 0) |
| 3220 charset = CHARSET_FROM_ID (charset_ascii); | 3252 charset = CHARSET_FROM_ID (charset_ascii); |
| 3221 else | 3253 else |
| 3569 *charbuf++ = c; | 3601 *charbuf++ = c; |
| 3570 char_offset++; | 3602 char_offset++; |
| 3571 } | 3603 } |
| 3572 else | 3604 else |
| 3573 { | 3605 { |
| 3574 components[component_idx++] = c; | 3606 if (component_idx < MAX_COMPOSITION_COMPONENTS * 2 + 1) |
| 3575 if (method == COMPOSITION_WITH_RULE | 3607 { |
| 3576 || (method == COMPOSITION_WITH_RULE_ALTCHARS | 3608 components[component_idx++] = c; |
| 3577 && composition_state == COMPOSING_COMPONENT_CHAR)) | 3609 if (method == COMPOSITION_WITH_RULE |
| 3578 composition_state++; | 3610 || (method == COMPOSITION_WITH_RULE_ALTCHARS |
| 3611 && composition_state == COMPOSING_COMPONENT_CHAR)) | |
| 3612 composition_state++; | |
| 3613 } | |
| 3614 else | |
| 3615 { | |
| 3616 MAYBE_FINISH_COMPOSITION (); | |
| 3617 *charbuf++ = c; | |
| 3618 char_offset++; | |
| 3619 } | |
| 3579 } | 3620 } |
| 3580 continue; | 3621 continue; |
| 3581 | 3622 |
| 3582 invalid_code: | 3623 invalid_code: |
| 3583 MAYBE_FINISH_COMPOSITION (); | 3624 MAYBE_FINISH_COMPOSITION (); |
