Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'\0\' is not correctly handled #526

Closed
triska opened this issue May 18, 2020 · 3 comments
Closed

'\0\' is not correctly handled #526

triska opened this issue May 18, 2020 · 3 comments

Comments

@triska
Copy link
Contributor

triska commented May 18, 2020

For a test case, please create a file with two bytes:

$ echo -n -e "\x0\x1" > f

Confirm the content (two bytes, in hex: 00 01) with:

$ hexdump f
0000000 00 01
0000002

However, the following unexpectedly succeeds:

:- use_module(library(pio)).
   true.
?- phrase_from_file([L], f).
   L = '\x1\'.

Expected: Failure, on the grounds that the file contains 2 bytes.

For comparison, the following works as intended:

$ echo -n -e "\x1\x2" > f

yielding:

?- phrase_from_file([A,B], f).
   A = '\x1\', B = '\x2\'.
@triska
Copy link
Contributor Author

triska commented May 18, 2020

Here is a shorter test case:

?- Xs = "\x0\".
   Xs = [].

Expected: Xs = "\x0\".

@ghost
Copy link

ghost commented May 18, 2020

This issue is linked to this one.

@triska
Copy link
Contributor Author

triska commented May 18, 2020

Ah yes, this is already filed, thank you a lot!

I'm closing this issue.

Normally, zero-bytes are very rare, but a major problem is that they easily arise during encryption. For instance, the following query should never succeed (since the length of the cipher text does not match the plain text), but now actually succeeds:

?- repeat,
   crypto_n_random_bytes(32, Key),
   crypto_n_random_bytes(12, IV),
   PlainText = "a",
   crypto_data_encrypt(PlainText, 'chacha20-poly1305', Key, IV, CipherText, []),
   \+ same_length(PlainText, CipherText).

This means that we cannot reliably use the symmetric encryption facilities as long as this issue is present.

@triska triska closed this as completed May 18, 2020
mthom added a commit that referenced this issue May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants