Uncaught AssertionError from CopybookParser.parseTree on copybooks with duplicated clauses (8 crash paths, JVM -ea independent)

未关闭
#878 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
54/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
scala, spark
领域
backend, data

调研方向

Start with ParserVisitor.scala at visitGroup and visitPrimitive (the issue identifies lines 506–509 and 796–800), then inspect the grammar rules that admit repeated clauses. Add parser tests for the listed duplicate clauses and for the duplicated SIGN control case. Done means malformed copybooks produce SyntaxErrorException consistently with and without JVM assertions enabled.

由索引模型根据 Issue 内容生成。

描述

bug

Describe the bug

CopybookParser.parseTree(...) — the public parser entry point used by the spark-cobol data source — throws an uncaught java.lang.AssertionError when a copybook contains a duplicated clause on the same data entry (e.g. two PICTURE, two OCCURS, two REDEFINES, duplicate VALUE).

  • Class: CWE-617 (Reachable Assertion). Availability impact only (no memory-safety).
  • Affected: za.co.absa.cobrix:cobol-parser_2.13:2.11.2 (Maven Central latest, 2026-10-12); the same asserts are still on master @ 2026-10-23 at the same lines.
  • Always-on: the crash is not a debug-only invariant failure — it fires with the default JVM flags (-da) too.

Three factors combine:

  1. The ANTLR grammar admits any number of these clauses (( ... )* repetition), so the invalid input passes syntax validation and reaches the visitor.
  2. The visitor enforces its "at most one / exactly one" invariants only with scala.Predef.assert (ParserVisitor.scala L506–509 visitGroup; L796–800 visitPrimitive). No semantic check rejects duplicates with the library's own SyntaxErrorException.
  3. scala.Predef.assert is @elidable(ASSERTION) and the published artifact has the calls compiled in, so they fire regardless of -ea/-da. Nothing catches between the visitor and the public API, so the Error escapes parseTree(...).

Confirmed crash paths (all deterministic, identical with and without -ea — 8 crash paths × 2 modes = 16/16; row 5 is the control, see below):

# data entry duplicated clause result failure location
1 primitive PIC X(2) PIC X(5) AssertionError visitPrimitive :800
2 primitive COMP COMP-3 (USAGE ×2) AssertionError visitPrimitive :797
3 primitive OCCURS 2 TIMES OCCURS 3 TIMES AssertionError visitPrimitive :798
4 primitive REDEFINES FOO REDEFINES BAR AssertionError visitPrimitive :796
5 primitive SIGN LEADING SEPARATE SIGN TRAILING SEPARATE SyntaxErrorException (control — grammar rejects, every tested flavor) — (:799 assert unreachable)
6 group REDEFINES A1 REDEFINES A2 AssertionError visitGroup :506
7 group COMP-3 PACKED-DECIMAL (usageGroup ×2) AssertionError visitGroup :507
8 group OCCURS 2 TIMES OCCURS 3 TIMES AssertionError visitGroup :508
9 group VALUE 'A' VALUE 'B' AssertionError visitGroup :509

Row 5 is the control: duplicated SIGN clauses are rejected with the library's intended error
type (SyntaxErrorException) in every flavor tested — adjacent, with SEPARATE CHARACTER,
reversed order, SIGN IS form, with another clause in between, and triple — in both -ea
and default JVM modes. It shows the error model that the other 8 paths bypass, and makes
the :799 (ctx.separateSign.size() < 2) assert unreachable from the accepted language —
that dead assert can be fixed or dropped together with the others.

Escape path / stack:

java.lang.AssertionError: assertion failed
	at scala.Predef$.assert(Predef.scala:264)
	at za.co.absa.cobrix.cobol.parser.antlr.ParserVisitor.visitPrimitive(ParserVisitor.scala:800)
	at za.co.absa.cobrix.cobol.parser.antlr.copybookParser$PrimitiveContext.accept(copybookParser.java:3559)
	...
	at za.co.absa.cobrix.cobol.parser.antlr.ANTLRParser$.parse(ANTLRParser.scala:88)
	at za.co.absa.cobrix.cobol.parser.CopybookParser$.parseTree(CopybookParser.scala:336)

Found by coverage-guided fuzzing (Jazzer 0.30 around parseTree) and minimized. A plain java.lang.Error aborts the calling Spark job, and re-reading the same input re-crashes deterministically (no retry tolerance).

Code snippet that caused the issue

import za.co.absa.cobrix.cobol.parser.CopybookParser

// duplicated PICTURE clause on one data entry (row 1)
val copybook =
  """      01  REC1.
    |          05  MES   PIC X(2) PIC X(5).
    |""".stripMargin

CopybookParser.parseTree(copybook)
// java.lang.AssertionError: assertion failed
//   at za.co.absa.cobrix.cobol.parser.antlr.ParserVisitor.visitPrimitive(ParserVisitor.scala:800)

Reachable the same way from Spark:

spark.read
  .format("cobol")
  .option("copybook_contents", copybook) // copybook with a duplicated clause
  .load(path)

The other 7 crash cases from the table (rows 2–4 and 6–9; each is a single duplicated clause) all reproduce identically — e.g. 05 F PIC X COMP COMP-3., 05 G PIC 9 OCCURS 2 TIMES OCCURS 3 TIMES., 05 A REDEFINES X REDEFINES Y., group-level REDEFINES/usage/OCCURS/VALUE duplicates, etc. A standalone Java probe covering all 9 cases was used (runs only against the published Maven artifacts, no rebuild).

Expected behavior

A malformed copybook should be rejected with the library's own za.co.absa.cobrix.cobol.parser.exceptions.SyntaxErrorException (as already happens for genuine syntax errors via the ANTLR error listener, and for semantic errors such as in checkBounds), with a clear message like "duplicate clause X on data entry Y" — not an uncaught java.lang.AssertionError.

The behaviour must be identical with and without -ea.

Context

  • Cobrix version: za.co.absa.cobrix:cobol-parser_2.13:2.11.2 (Maven Central latest, published 2026-10-12); same issue on master @ 2026-10-23
  • Spark version: n/a for the standalone repro (parser-level); also reachable via spark-cobol
  • Scala version: 2.13.18 (scala-library; artifact built for 2.13)
  • Operating system: Linux x86_64 (OpenJDK 21.0.13 Temurin)

CVSS v3.1 (suggested, copybook from a not-fully-trusted feed): AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H → 6.5 (Medium).

Copybook (if possible)

(rows 6–9: each line is its own one-entry copybook; the error fires on the line the probe focuses on — shown together for compactness)
Primary crashing copybook (realistic multi-field layout; note 10 MES carries two PICTURE clauses):

      01  MESSAGE.
          05  MESCAGE-TOP.
              10  MESSAGE-TYPE            PIC X(2).
              10  MES       PIC X         PIC X(1).
              10  MESSAGE-DATA            PIC X(10).

Minimal header-only group variants (rows 6–9):

      01  R.
          05  A   REDEFINES X REDEFINES Y.
          05  B   COMP-3 PACKED-DECIMAL.
          05  C   OCCURS 2 TIMES OCCURS 3 TIMES.
          05  D   VALUE 'A' VALUE 'B'.

Attachments: standalone probe PocAssertFamily.java (9 cases, prints crash location per case), full probe output for -ea and -da (identical for the 8 crash cases, 16/16), and the fuzzer crash input + Java reproducer. Data file is not needed to reproduce (the crash is parse-level and data-independent), but a small one can be attached if useful.

poc_results.txt
PocAssertFamily.java
Crash_cc10fa3d5bfb9296bd39fee83dd200380925f302.java
crash-cc10fa3d5bfb9296bd39fee83dd200380925f302.txt

主要语言
Scala
星标
170
派生
96
平均合并
7 天 5 小时
30 天内合并 PR
4

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

AbsaOSS/cobrix 的其他 Issue

查看 AbsaOSS/cobrix 的全部 Issue

相似的 Issue

更多 Scala Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。