Fix AU ABN accepting some invalid leading-zero numbers#2109
Open
jichaowang02-lang wants to merge 1 commit into
Open
Fix AU ABN accepting some invalid leading-zero numbers#2109jichaowang02-lang wants to merge 1 commit into
jichaowang02-lang wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Description
The ABN checksum remaps a leading-zero first digit to 9:
The official ABR algorithm simply subtracts 1 from the first (left-most) digit, so a leading
0becomes-1. Remapping it to9instead shifts the weighted sum by 100 (≡ 11 mod 89), which admits some invalid 11-digit numbers beginning with0as valid ABNs — a false positive:Valid ABNs never start with
0, and under the official literal subtract-1,00000000560gives 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
Tests
Adds the case
00000000560(expected: not detected) — it fails before the fix (was accepted at score 1.0). The existing valid ABN51824753556and invalid-checksum cases are unchanged.