Skip to content

Test/base64#245

Closed
benjamin-si wants to merge 5 commits into
ebics-api:3.xfrom
benjamin-si:test/base64
Closed

Test/base64#245
benjamin-si wants to merge 5 commits into
ebics-api:3.xfrom
benjamin-si:test/base64

Conversation

@benjamin-si

Copy link
Copy Markdown

No description provided.

@benjamin-si

Copy link
Copy Markdown
Author

Hey @andrew-svirin, this is tests for base64 error.

@andrew-svirin

Copy link
Copy Markdown
Member

@benjamin-si there are some conflicts there.

@benjamin-si

Copy link
Copy Markdown
Author

done

@andrew-svirin

andrew-svirin commented Jul 13, 2026

Copy link
Copy Markdown
Member

@benjamin-si

    PR #245 tests: flawed test design                                                     
                                                                                           
     All 3 "bug" tests (Test2/3/4) fail, but not for the reason the PR claims. The         
     tests assert assertEquals($original, $decoded) where $original = 1023 bytes, but      
     they feed in truncated base64 (1025-1027 chars sliced from a 1364-char string).       
     The data was chopped off before decoding — it's mathematically impossible to          
     recover 1023 bytes from that.                                                         
     ┌────────┬───────────┬────────────┬────────────┬─────────┬───────────────────────┐    
     │Test    │Input chars│decodeBuffer│base64_decod│Match?   │PR assertion vs        │    
     │        │           │            │e           │         │original               │    
     ├────────┼───────────┼────────────┼────────────┼─────────┼───────────────────────┤    
     │2 (1025)│1025       │768 bytes   │768 bytes   │Identical│FAIL (expects 1023)    │    
     ├────────┼───────────┼────────────┼────────────┼─────────┼───────────────────────┤    
     │3 (1026)│1026       │769 bytes   │769 bytes   │Identical│FAIL (expects 1023)    │    
     ├────────┼───────────┼────────────┼────────────┼─────────┼───────────────────────┤    
     │4 (1027)│1027       │770 bytes   │770 bytes   │Identical│FAIL (expects 1023)    │    
     └────────┴───────────┴────────────┴────────────┴─────────┴───────────────────────┘    
                                                                                           
     The critical column: decodeBuffer output is identical to base64_decode of the         
     full input. There is no data loss — the PR's assertEquals(original) is comparing      
     against the wrong expected value. 

     Real scenario: properly encoded unpadded base64                                       
                                                                                           
     All sizes pass — decodeBuffer matches base64_decode exactly, including remainders     
     of 2, 3, 343, and 523 bytes.                                                          
                                                                                           
     Verdict 

     The bug described in PR #245 does not exist. The tests are written incorrectly:       
     they truncate base64 data (destroying encoded bytes) then assert the original         
     data should be recovered. The decodeBuffer chunked decoder produces byte-             
     identical output to PHP's native base64_decode() on every input tested.

@andrew-svirin

Copy link
Copy Markdown
Member

Found some buffering corner case. But it is with Zip. So you can also check if it somehow impact (3cdb8f2#diff-0c4af4208c073350c777161e27c65eb791835666a833247f04f6dc3cc4132aa1R123)

@benjamin-si

Copy link
Copy Markdown
Author

Mhh, i will retry new test

@benjamin-si

Copy link
Copy Markdown
Author

Last try for me.

I added testBuggyChunkedBase64DecodeCorruptsAesCiphertext

@benjamin-si

Copy link
Copy Markdown
Author

I will fix it localy if you can't reproduce it

@andrew-svirin

Copy link
Copy Markdown
Member

Maybe you have some PHP pedefined consts. Because localy tests from MR pass. Yes, if you can localy to fix, then make it locally.

@benjamin-si

Copy link
Copy Markdown
Author

hey @andrew-svirin , updated to last version this morning is working now

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants