Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 270ab5440acad9966967a0dba433ca16fd255c05d01dd576e1c2459584c665be
Ticket: 73bb42fb3f35cd613af6fcea465e35bbfd352216
Panic "Buffer Underflow, BUFFER_PADDING not enough"
User & Date: apnadkarni on 2025-03-05 05:54:52
Changes

  1. icomment:
    While the panic is the same, the underlying bug I believe is separate from what was reported in this ticket.
    
    A slightly simpler version to reproduce for debugging.
    
    ```
    % writeFile x.txt binary \xD6[string repeat _ 20]
    % set f [open x.txt]
    file257cf8b69f0
    % fconfigure $f -blocking 0 -buffersize 10 -translation lf -eofchar {}
    % read $f 1
    Buffer Underflow, BUFFER_PADDING not enough
    ```
    
    I understand what the problem is. Kind of. The encoding routines return an error (as they should). ReadChars overwrites that code with TCL_OK (presumably to allow callers up the stack to retrieve whatever could be successfully read). Because the error was right at the first byte, no characters are decoded so further in ReadChars it presumes more data is needed and returns -1. The caller DoReadChars then checks for EOF and since that is not set, repeats the call.
    
    Possible fix [here](https://core.tcl-lang.org/tcl/info/1d45e395d9095e3d) which checks for encoding error flag in addition to eof but not sure that is the right place or if it is complete. Test suite passes (fwiw) as does the bug test.
    
  2. login: "apnadkarni"
  3. mimetype: "text/x-markdown"