Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
No build reason found for config:riscv64
home:Ledest:erlang:26
erlang
0325-binary-module-Always-reject-bitstrings.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0325-binary-module-Always-reject-bitstrings.patch of Package erlang
From 0eb56f4fe8057c32d6ea86dedee3adc0b5082d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org> Date: Wed, 6 Sep 2023 05:54:57 +0200 Subject: [PATCH] binary module: Always reject bitstrings The call `binary:copy(<<1:1>>, 0)` would return an empty binary instead of raising an exception. Similarly, calls to `binary:part/{2,3}` attempting to extract 0 bytes at position 0 of a bitstring would return an empty binary instead of raising an exception. --- erts/emulator/beam/erl_bif_binary.c | 16 ++++++++++------ lib/stdlib/test/binary_module_SUITE.erl | 7 +++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/erts/emulator/beam/erl_bif_binary.c b/erts/emulator/beam/erl_bif_binary.c index cac5f8bab9..6bb59b3157 100644 --- a/erts/emulator/beam/erl_bif_binary.c +++ b/erts/emulator/beam/erl_bif_binary.c @@ -1965,11 +1965,15 @@ BIF_RETTYPE erts_binary_part(Process *p, Eterm binary, Eterm epos, Eterm elen) goto badarg; } + ERTS_GET_REAL_BIN(binary, orig, offset, bit_offset, bit_size); + + if (bit_size != 0) { + goto badarg; + } + hp = HeapFragOnlyAlloc(p, EXTRACT_SUB_BIN_HEAP_NEED); hp_end = hp + EXTRACT_SUB_BIN_HEAP_NEED; - ERTS_GET_REAL_BIN(binary, orig, offset, bit_offset, bit_size); - result = erts_extract_sub_binary(&hp, orig, binary_bytes(orig), (offset + pos) * 8 + bit_offset, len * 8); @@ -2471,14 +2475,14 @@ static BIF_RETTYPE do_binary_copy(Process *p, Eterm bin, Eterm en) if (!term_to_Uint(en, &n)) { goto badarg; } - if (!n) { - Eterm res_term = erts_new_heap_binary(p,NULL,0,&bytes); - BIF_RET(res_term); - } ERTS_GET_BINARY_BYTES(bin,bytes,bit_offs,bit_size); if (bit_size != 0) { goto badarg; } + if (n == 0) { + Eterm res_term = erts_new_heap_binary(p, NULL, 0, &bytes); + BIF_RET(res_term); + } size = binary_size(bin); target_size = size * n; diff --git a/lib/stdlib/test/binary_module_SUITE.erl b/lib/stdlib/test/binary_module_SUITE.erl index 21593b4f49..27eb7de92c 100644 --- a/lib/stdlib/test/binary_module_SUITE.erl +++ b/lib/stdlib/test/binary_module_SUITE.erl @@ -125,6 +125,11 @@ badargs(Config) when is_list(Config) -> ?MASK_ERROR( binary_part(make_unaligned(<<1,2,3>>),{16#FF, -16#7FFF})), + badarg = ?MASK_ERROR(binary:part(<<1:1>>, id({0,0}))), + badarg = ?MASK_ERROR(binary_part(<<1:1>>, id({0,0}))), + badarg = ?MASK_ERROR(binary:part(<<1:1>>, id(0), 0)), + badarg = ?MASK_ERROR(binary_part(<<1:1>>, id(0), 0)), + badarg = ?MASK_ERROR( binary:bin_to_list(<<1,2,3>>,{16#FF, @@ -800,6 +805,8 @@ copy(Config) when is_list(Config) -> true = RS =:= RS2, false = erts_debug:same(RS, RS2), <<>> = ?MASK_ERROR(binary:copy(<<1,2,3>>,0)), + badarg = ?MASK_ERROR(binary:copy(<<1:1>>,0)), + badarg = ?MASK_ERROR(binary:copy(<<1,2,3:3>>,0)), badarg = ?MASK_ERROR(binary:copy(<<1,2,3:3>>,2)), badarg = ?MASK_ERROR(binary:copy([],0)), <<>> = ?MASK_ERROR(binary:copy(<<>>,0)), -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor