• Venkata Sidagam's avatar
    Bug #17760379 COLLATIONS WITH CONTRACTIONS BUFFER-OVERFLOW THEMSELVES IN THE FOOT · ff061486
    Venkata Sidagam authored
    Description: A typo in create_tailoring() causes the "contraction_flags" to be written
    into cs->contractions in the wrong place. This causes two problems:
    (1) Anyone relying on `contraction_flags` to decide "could this character be
    part of a contraction" is 100% broken.
    (2) Anyone relying on `contractions` to determine the weight of a contraction
    is mostly broken
    
    Analysis: When we are preparing the contraction in create_tailoring(), we are corrupting the 
    cs->contractions memory location which is supposed to store the weights(8k) + contraction information(256 bytes). We started storing the contraction information after the 4k location. This is because of logic flaw in the code.
    
    Fix: When we create the contractions, we need to calculate the contraction with (char*) (cs->contractions + 0x40*0x40) from ((char*) cs->contractions) + 0x40*0x40. This makes the "cs->contractions" to move to 8k bytes and stores the contraction information from there. Similarly when we are calculating it for like range queries we need to calculate it from the 8k bytes onwards, this can be done by changing the logic to (const char*) (cs->contractions + 0x40*0x40). And for ucs2 charsets we need to modify the my_cs_can_be_contraction_head() and my_cs_can_be_contraction_tail() to point to 8k+ locations.
    ff061486
m_ctype.h 26.7 KB