Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 6c1881e6a47137618c4faccd0395f99e53d8083b8ddacf4b17f305b8e3f91b2f
Ticket: d07f42998da94cfe0c9cebc73c5cecc63f99f421
Tcl_CreateObjCommand2 argument truncation and misleading error message
User & Date: apnadkarni on 2023-04-30 07:56:37
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-markdown"
  4. comment changed to:
    The new Tcl_CreateObjCommand2 API permits creation of commands which accept more than `2**31` arguments. The following anomalous behavior is seen.
    
    When called through the 8.x wrapper, argument count wraps around. Instead, an error should be raised.
    
    ```
    % set cmd [testbigdata list 0x100000008]; llength $cmd
    4294967304
    % ledit cmd 0 0 testcmdobj2 ; llength $cmd
    4294967304
    % testcmdinfo call $cmd
    8 1 7
    ```
    
    `testcmdobj2` uses the Tcl_CreateObjCommand2 API to register itself and accepts ptrdiff_t sized counts. Its return is objc, first and last argument. As seen above, 0x100000008 is wraps around to 8. An error should be raised instead.
    
    Conversely, an old style command (e.g. lappend) also truncates when called through the new or old API when called with more than 2**32 arguments.
    
    ```
    % set l [testbigdata list 0x100000008]; llength $l
    4294967304
    % ledit l 0 1 lappend x ; llength $l
    4294967304
    % testcmdinfo call $l
    2 3 4 5 6 7
    % unset x
    % testcmdinfo call2 $l
    2 3 4 5 6 7
    ```
    
    When called with objc between INT_MAX and UINT_MAX, it does give an error but a misleading one.
    
    ```
    % set cmd [testbigdata list 0x80000008]; llength $cmd
    2147483656
    % ledit cmd 0 1 lappend X ; llength $cmd
    2147483656
    % testcmdinfo call $cmd
    wrong # args: should be "lappend varName ?value ...?"
    % testcmdinfo call2 $cmd
    wrong # args: should be "lappend varName ?value ...?"
    ```
    
    This error message, while not entirely wrong, is misleading and confusing since the error message text for lappend seems to indicate any number of arguments are accepted. A more informative error would be one that states that max argument count exceeded.
    
  5. foundin changed to: "9.0"
  6. is_private changed to: "0"
  7. login: "apnadkarni"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "9546e9877f1a8899e25a89082561ee694e7fb402"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "apnadkarni"
  14. subsystem changed to: "- New Builtin Commands"
  15. title changed to:
    Tcl_CreateObjCommand2 misleading error message and argument truncation
    
  16. type changed to: "Bug"