Skip to content

COBOL engine: the last DATA DIVISION entry takes its USAGE from the PROCEDURE DIVISION (DISPLAY verb, 'BINARY' literal) -- wrong byte length #4329

Closed

Description

@squid-protocol

Problem

The record reader (mainframe_boundary.py, _records) searches for a data entry's USAGE in window, which runs from the entry's name to the next level number or _ENTRY_LIMIT (600 chars). It does not stop at the entry's separator period. For the last DATA DIVISION entry, the window runs into the PROCEDURE DIVISION. So the first usage word there becomes the entry's USAGE: a DISPLAY verb, or a usage word inside a literal (MOVE 'BINARY' TO ...).

# mainframe_boundary.py (main 25f92338), ~l.1029-1035
entry = _ENTRY_END.split(_QUOTED.sub(..., window), maxsplit=1)[0]   # cut at the period, literals blanked
if _NATIONAL_USAGE.search(entry):                                    # NATIONAL already uses `entry`
    usage = "NATIONAL"
else:
    usage_match = _USAGE_CLAUSE.search(window)                       # every other usage still uses `window`

The comment above it already says the last item's window "runs on into" the procedure, but only NATIONAL was moved onto entry.

Evidence

  • estate-crucible v0.1.0 (Epic: estate-crucible -- a synthetic mainframe estate whose answer key is generated with it #4317), keyed:

    • estate/apps/ACCT/cobol/ACCTUPD.cbl:16: 01 WS-MSG PIC X(40). gets usage DISPLAY (taken from DISPLAY WS-MSG in the procedure).
    • estate/apps/ACCT/cobol/ACCTAUD.cbl:9: 01 LK-UPD-CONTROL. (a group, then COPY UPDCTL.) gets DISPLAY too.
  • Minimal reproducers, main 25f9233.

    1. WS-MSG gets usage DISPLAY:
           IDENTIFICATION DIVISION.
           PROGRAM-ID. USGLEAK.
           DATA DIVISION.
           WORKING-STORAGE SECTION.
           01  WS-COUNT               PIC 9(4) VALUE 0.
           01  WS-MSG                 PIC X(40).
           PROCEDURE DIVISION.
           MAIN-PARA.
               MOVE 'HELLO' TO WS-MSG
               DISPLAY WS-MSG
               GOBACK.
    1. Worse, a literal in the procedure changes the storage. WS-LEN PIC 9(4) gets usage BINARY, and GalaxyIR.record_layout gives 2 bytes instead of 4:
           IDENTIFICATION DIVISION.
           PROGRAM-ID. USGBIN.
           DATA DIVISION.
           WORKING-STORAGE SECTION.
           01  WS-MODE                PIC X(8).
           01  WS-LEN                 PIC 9(4).
           PROCEDURE DIVISION.
           MAIN-PARA.
               MOVE 'BINARY' TO WS-MODE
               MOVE 12 TO WS-LEN
               GOBACK.

Impact

Every program's last WORKING-STORAGE / LINKAGE entry is exposed. When the first usage word after it is DISPLAY, the result happens to be harmless for an alphanumeric item. When it is COMP / BINARY / PACKED-DECIMAL / INDEX / POINTER (as a word or inside a literal), the item's byte length is wrong. That flows into record layouts, COMMAREA contracts (LINKAGE is usually last), and translated Java field types.

Acceptance criteria

  • USAGE (and any other clause the reader takes from window) is searched only in entry: the entry's own text, up to its separator period, with literals blanked.
  • Both reproducers: WS-MSG usage None, WS-LEN usage None and layout 4 bytes.
  • estate-crucible: the data_items checks for ACCTUPD WS-MSG and ACCTAUD LK-UPD-CONTROL pass.

Related: #3246 (record_data), #3816 (the NATIONAL fix that already uses entry), #4317 (estate-crucible; planted there as H-0009 from v0.2.0).

Found by: estate-crucible v0.1.0 scorecard (#4324).

Activity

  1. added
    bug
    core-engine
    legacy-modernization
    priority: high
    on Oct 4, 2026
  2. squid-protocol commented on Oct 5, 2026

    @squid-protocol
    OwnerAuthor

    Fixed by train D, #4398 (merged).

  3. added
    scope:sweep
    era:2
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-engineera:2legacy-modernizationpriority: highscope:sweep

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions