HaxeFoundation / HaxeFoundation/haxe

[php] Wrong addbytes for BytesBuffer

Open
#11,369 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

The code below will return for Eval target:
```
1) Ki: 36363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636
2) Ki: 3636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363600000001
```
but will give wrong result for php:
```
1) Ki: 36363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636
2) Ki: 00000001
````

Here is the example:
```haxe
var Ki = new haxe.io.BytesBuffer();
var msg = Bytes.ofHex("00000001");
var key = Bytes.ofHex("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
for (i in 0...key.length) {
Ki.addByte(key.get(i) ^ 0x36);
}
trace("1) Ki: "+Ki.getBytes().toHex());
Ki.add(msg);
trace("2) Ki: "+Ki.getBytes().toHex());
```

Tested on Haxe 4.3.1

Contributor guide

Open the contributing guide

Research direction

Run the provided haxe.io.BytesBuffer example for the PHP target and compare its output with the other target shown. Then trace the PHP-target implementation used by BytesBuffer.add and addBytes; done means appending the four-byte message preserves the existing bytes and produces the expected second hex value.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.