Skip to content

Fix AU ABN accepting some invalid leading-zero numbers#2109

Open
jichaowang02-lang wants to merge 1 commit into
data-privacy-stack:mainfrom
jichaowang02-lang:fix/au-abn-leading-zero-false-positive
Open

Fix AU ABN accepting some invalid leading-zero numbers#2109
jichaowang02-lang wants to merge 1 commit into
data-privacy-stack:mainfrom
jichaowang02-lang:fix/au-abn-leading-zero-false-positive

Conversation

@jichaowang02-lang

Copy link
Copy Markdown
Contributor

Change Description

The ABN checksum remaps a leading-zero first digit to 9:

abn_list[0] = 9 if abn_list[0] == 0 else abn_list[0] - 1

The official ABR algorithm simply subtracts 1 from the first (left-most) digit, so a leading 0 becomes -1. Remapping it to 9 instead shifts the weighted sum by 100 (≡ 11 mod 89), which admits some invalid 11-digit numbers beginning with 0 as valid ABNs — a false positive:

AuAbnRecognizer().analyze("00000000560", ["AU_ABN"])   # wrongly recognized (score 1.0)

Valid ABNs never start with 0, and under the official literal subtract-1, 00000000560 gives a non-zero remainder mod 89, so it is correctly invalid.

Fix

Use the literal abn_list[0] - 1. This is identical for first digits 1-9, so no valid ABN is affected; only invalid leading-zero numbers (which the official algorithm rejects) are now correctly rejected.

Checklist

  • I have reviewed the contribution guidelines
  • I have added tests to cover my changes
  • All new and existing tests passed

Tests

$ pytest tests/test_au_abn_recognizer.py -q
9 passed

Adds the case 00000000560 (expected: not detected) — it fails before the fix (was accepted at score 1.0). The existing valid ABN 51824753556 and invalid-checksum cases are unchanged.

The ABN checksum remapped a leading-zero first digit to 9
(`abn_list[0] = 9 if abn_list[0] == 0 else abn_list[0] - 1`). The official ABR
algorithm simply subtracts 1 from the first (left-most) digit, so a leading 0
becomes -1. Remapping it to 9 instead shifts the weighted sum by 100 (= 11 mod
89) and admits some invalid 11-digit numbers beginning with 0 as valid ABNs —
a false positive (e.g. 00000000560). Valid ABNs never start with 0.

Use the literal subtract-1. This is identical for first digits 1-9, so no
valid ABN is affected; only invalid leading-zero numbers, which the official
algorithm rejects, are now correctly rejected.

Adds a regression case (00000000560) that was wrongly accepted before.
Copilot AI review requested due to automatic review settings June 27, 2026 09:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants