Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NULL values in field records are not supported #17

Merged
merged 1 commit into from
Feb 28, 2024

Conversation

fdie
Copy link
Contributor

@fdie fdie commented Feb 28, 2024

Issue analysis

p1_mysql_bin.erl:

decode_resultset_row(LogFun, [Type | TypeRest], Column, Null, Value, Acc) ->
    case (1 bsl Column) band Null of
   	    1 -> ...   	    
  • Obviously, this code is wrong since it could be 1 for Column 0 only, but any column could have a "NULL" value...

  • We had the below crash because a record of a table had a last column with a "NULL" value,
    resulting in a correct decoding of all columns but the last column since
    a string value decoding is attempted but fails (due to lack of data, see <<>>).
    This column is erroneously not considered having a "NULL" value due to a "NULL bitmap" handling issue.

** {function_clause,                                                                                                                        
       [{p1_mysql_bin,decode_var_int,                                 
            [<<>>],                                                   
            [{file,"/build/deps/p1_mysql/src/p1_mysql_bin.erl"},{line,194}]},                                                               
        {p1_mysql_bin,decode_var_string,1,                            
            [{file,"/build/deps/p1_mysql/src/p1_mysql_bin.erl"},{line,181}]},                                                               
        {p1_mysql_bin,decode_resultset_row,6,                         
            [{file,"/build/deps/p1_mysql/src/p1_mysql_bin.erl"},{line,308}]},                                                               
        {p1_mysql_bin,get_resultset_rows,4,                           
            [{file,"/build/deps/p1_mysql/src/p1_mysql_bin.erl"},{line,318}]},                                                               
        {p1_mysql_bin,get_execute_stmt_response,3,                    
            [{file,"/build/deps/p1_mysql/src/p1_mysql_bin.erl"},{line,136}]},                                                               
        {p1_mysql_bin,execute,5,                                      
            [{file,"/build/deps/p1_mysql/src/p1_mysql_bin.erl"},{line,78}]},                                                                
        {p1_mysql_conn,handle_info,2,                                 
            [{file,"src/p1_mysql_conn.erl"},{line,408}]},             
        {gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,1123}]}]} 

The issue is due to a wrong decoding of the "NULL" bitmap.
The spec https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_binary_resultset.html
describes a "NULL bitmap" with a bit for each column index and with 2 leading bits that should be ignored.
Those 2 bits are not taken into account in the current source code which causes a 2 bits shift
in the bitmap integer value.

Patch

We tried a table with records having "NULL" values at position 0, 3 and the last column 5 and the resultset
is correctly decoded once the provided patch has been applied.
Some unit tests of the binary protocol would be helpful ;-)

@prefiks
Copy link
Member

prefiks commented Feb 28, 2024

Looks good, i will merge it.

@prefiks prefiks merged commit 05e5fb2 into processone:master Feb 28, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants