aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c73
1 files changed, 57 insertions, 16 deletions
diff --git a/src/coding.c b/src/coding.c
index 9c617a3f8e4..286fc5cd0a9 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -2758,6 +2758,7 @@ detect_coding_iso_2022 (coding, detect_info)
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
@@ -2826,10 +2827,20 @@ detect_coding_iso_2022 (coding, detect_info)
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
@@ -2900,6 +2911,8 @@ detect_coding_iso_2022 (coding, detect_info)
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 }
@@ -2924,9 +2937,17 @@ detect_coding_iso_2022 (coding, detect_info)
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 }
@@ -3043,6 +3064,8 @@ detect_coding_iso_2022 (coding, detect_info)
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 \
@@ -3190,10 +3213,15 @@ decode_coding_iso_2022 (coding)
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
@@ -3210,10 +3238,14 @@ decode_coding_iso_2022 (coding)
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)
@@ -3571,11 +3603,20 @@ decode_coding_iso_2022 (coding)
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