mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 13:08:49 +00:00
parent
18b06f3768
commit
7be8a1707c
5 changed files with 14 additions and 14 deletions
|
@ -475,7 +475,7 @@ The exit status of the last run command substitution is available in the <a href
|
||||||
|
|
||||||
Only part of the output can be used, see <a href='#expand-index-range'>index range expansion</a> for details.
|
Only part of the output can be used, see <a href='#expand-index-range'>index range expansion</a> for details.
|
||||||
|
|
||||||
Fish has a default limit of 10 MiB on the amount of data a command substitution can output. If the limit is exceeded the entire command, not just the substitution, is failed and `$status` is set to 122. You can modify the limit by setting the `FISH_READ_BYTE_LIMIT` variable at any time including in the environment before fish starts running. If you set it to zero then no limit is imposed. This is a safety mechanism to keep the shell from consuming an too much memory if a command outputs an unreasonable amount of data. Note that this limit also affects how much data the `read` command will process.
|
Fish has a default limit of 10 MiB on the amount of data a command substitution can output. If the limit is exceeded the entire command, not just the substitution, is failed and `$status` is set to 122. You can modify the limit by setting the `fish_read_limit` variable at any time including in the environment before fish starts running. If you set it to zero then no limit is imposed. This is a safety mechanism to keep the shell from consuming an too much memory if a command outputs an unreasonable amount of data. Note that this limit also affects how much data the `read` command will process.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ Otherwise, it is set to 0.
|
||||||
In order to protect the shell from consuming too many system resources, `read` will only consume a
|
In order to protect the shell from consuming too many system resources, `read` will only consume a
|
||||||
maximum of 10 MiB (1048576 bytes); if the terminator is not reached before this limit then VARIABLE
|
maximum of 10 MiB (1048576 bytes); if the terminator is not reached before this limit then VARIABLE
|
||||||
is set to empty and the exit status is set to 122. This limit can be altered with the
|
is set to empty and the exit status is set to 122. This limit can be altered with the
|
||||||
`FISH_READ_BYTE_LIMIT` variable. If set to 0 (zero), the limit is removed.
|
`fish_read_limit` variable. If set to 0 (zero), the limit is removed.
|
||||||
|
|
||||||
\subsection read-history Using another read history file
|
\subsection read-history Using another read history file
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
||||||
// Limit `read` to 10 MiB (bytes not wide chars) by default. This can be overridden by the
|
// Limit `read` to 10 MiB (bytes not wide chars) by default. This can be overridden by the
|
||||||
// FISH_READ_BYTE_LIMIT variable.
|
// fish_read_limit variable.
|
||||||
#define READ_BYTE_LIMIT 10 * 1024 * 1024
|
#define READ_BYTE_LIMIT 10 * 1024 * 1024
|
||||||
size_t read_byte_limit = READ_BYTE_LIMIT;
|
size_t read_byte_limit = READ_BYTE_LIMIT;
|
||||||
|
|
||||||
|
@ -680,11 +680,11 @@ bool env_set_pwd() {
|
||||||
/// Allow the user to override the limit on how much data the `read` command will process.
|
/// Allow the user to override the limit on how much data the `read` command will process.
|
||||||
/// This is primarily for testing but could be used by users in special situations.
|
/// This is primarily for testing but could be used by users in special situations.
|
||||||
void env_set_read_limit() {
|
void env_set_read_limit() {
|
||||||
auto read_byte_limit_var = env_get(L"FISH_READ_BYTE_LIMIT");
|
auto read_byte_limit_var = env_get(L"fish_read_limit");
|
||||||
if (!read_byte_limit_var.missing_or_empty()) {
|
if (!read_byte_limit_var.missing_or_empty()) {
|
||||||
size_t limit = fish_wcstoull(read_byte_limit_var->as_string().c_str());
|
size_t limit = fish_wcstoull(read_byte_limit_var->as_string().c_str());
|
||||||
if (errno) {
|
if (errno) {
|
||||||
debug(1, "Ignoring FISH_READ_BYTE_LIMIT since it is not valid");
|
debug(1, "Ignoring fish_read_limit since it is not valid");
|
||||||
} else {
|
} else {
|
||||||
read_byte_limit = limit;
|
read_byte_limit = limit;
|
||||||
}
|
}
|
||||||
|
@ -846,7 +846,7 @@ static void setup_var_dispatch_table() {
|
||||||
var_dispatch_table.emplace(L"fish_escape_delay_ms", handle_escape_delay_change);
|
var_dispatch_table.emplace(L"fish_escape_delay_ms", handle_escape_delay_change);
|
||||||
var_dispatch_table.emplace(L"LINES", handle_term_size_change);
|
var_dispatch_table.emplace(L"LINES", handle_term_size_change);
|
||||||
var_dispatch_table.emplace(L"COLUMNS", handle_term_size_change);
|
var_dispatch_table.emplace(L"COLUMNS", handle_term_size_change);
|
||||||
var_dispatch_table.emplace(L"FISH_READ_BYTE_LIMIT", handle_read_limit_change);
|
var_dispatch_table.emplace(L"fish_read_limit", handle_read_limit_change);
|
||||||
var_dispatch_table.emplace(L"fish_history", handle_fish_history_change);
|
var_dispatch_table.emplace(L"fish_history", handle_fish_history_change);
|
||||||
var_dispatch_table.emplace(L"TZ", handle_tz_change);
|
var_dispatch_table.emplace(L"TZ", handle_tz_change);
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,13 +135,13 @@ rm $path
|
||||||
# The following tests verify that `read` correctly handles the limit on the
|
# The following tests verify that `read` correctly handles the limit on the
|
||||||
# number of bytes consumed.
|
# number of bytes consumed.
|
||||||
#
|
#
|
||||||
set FISH_READ_BYTE_LIMIT 8192
|
set fish_read_limit 8192
|
||||||
set line abcdefghijklmnopqrstuvwxyz
|
set line abcdefghijklmnopqrstuvwxyz
|
||||||
|
|
||||||
# Ensure the `read` command terminates if asked to read too much data. The var
|
# Ensure the `read` command terminates if asked to read too much data. The var
|
||||||
# should be empty. We throw away any data we read if it exceeds the limit on
|
# should be empty. We throw away any data we read if it exceeds the limit on
|
||||||
# what we consider reasonable.
|
# what we consider reasonable.
|
||||||
yes $line | dd bs=1024 count=(math "1 + $FISH_READ_BYTE_LIMIT / 1024") ^/dev/null | read --null x
|
yes $line | dd bs=1024 count=(math "1 + $fish_read_limit / 1024") ^/dev/null | read --null x
|
||||||
if test $status -ne 122
|
if test $status -ne 122
|
||||||
echo reading too much data did not terminate with failure status
|
echo reading too much data did not terminate with failure status
|
||||||
end
|
end
|
||||||
|
@ -155,7 +155,7 @@ and echo reading too much data resulted in a var with unexpected data
|
||||||
# Ensure the `read` command terminates if asked to read too much data even if
|
# Ensure the `read` command terminates if asked to read too much data even if
|
||||||
# given an explicit limit. The var should be empty. We throw away any data we
|
# given an explicit limit. The var should be empty. We throw away any data we
|
||||||
# read if it exceeds the limit on what we consider reasonable.
|
# read if it exceeds the limit on what we consider reasonable.
|
||||||
yes $line | read --null --nchars=(math "$FISH_READ_BYTE_LIMIT + 1") x
|
yes $line | read --null --nchars=(math "$fish_read_limit + 1") x
|
||||||
if test $status -ne 122
|
if test $status -ne 122
|
||||||
echo reading too much data did not terminate with failure status
|
echo reading too much data did not terminate with failure status
|
||||||
end
|
end
|
||||||
|
@ -178,21 +178,21 @@ if test $exp_length -ne $act_length
|
||||||
end
|
end
|
||||||
|
|
||||||
# Confirm we can read exactly up to the limit.
|
# Confirm we can read exactly up to the limit.
|
||||||
yes $line | read --null --nchars $FISH_READ_BYTE_LIMIT x
|
yes $line | read --null --nchars $fish_read_limit x
|
||||||
if test $status -ne 0
|
if test $status -ne 0
|
||||||
echo the read of the max amount of data with --nchars failed unexpectedly
|
echo the read of the max amount of data with --nchars failed unexpectedly
|
||||||
end
|
end
|
||||||
if test (string length "$x") -ne $FISH_READ_BYTE_LIMIT
|
if test (string length "$x") -ne $fish_read_limit
|
||||||
echo reading the max amount of data with --nchars failed the length test
|
echo reading the max amount of data with --nchars failed the length test
|
||||||
end
|
end
|
||||||
|
|
||||||
# Same as previous test but limit the amount of data fed to `read` rather than
|
# Same as previous test but limit the amount of data fed to `read` rather than
|
||||||
# using the `--nchars` flag.
|
# using the `--nchars` flag.
|
||||||
yes $line | dd bs=1024 count=(math "$FISH_READ_BYTE_LIMIT / 1024") ^/dev/null | read --null x
|
yes $line | dd bs=1024 count=(math "$fish_read_limit / 1024") ^/dev/null | read --null x
|
||||||
if test $status -ne 0
|
if test $status -ne 0
|
||||||
echo the read of the max amount of data failed unexpectedly
|
echo the read of the max amount of data failed unexpectedly
|
||||||
end
|
end
|
||||||
if test (string length "$x") -ne $FISH_READ_BYTE_LIMIT
|
if test (string length "$x") -ne $fish_read_limit
|
||||||
echo reading the max amount of data with --nchars failed the length test
|
echo reading the max amount of data with --nchars failed the length test
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# This tests various corner cases involving command substitution. Most
|
# This tests various corner cases involving command substitution. Most
|
||||||
# importantly the limits on the amount of data we'll substitute.
|
# importantly the limits on the amount of data we'll substitute.
|
||||||
|
|
||||||
set FISH_READ_BYTE_LIMIT 512
|
set fish_read_limit 512
|
||||||
|
|
||||||
function subme
|
function subme
|
||||||
set -l x (string repeat -n $argv x)
|
set -l x (string repeat -n $argv x)
|
||||||
|
|
Loading…
Reference in a new issue