PostgreSQL: Don't treat user types containing 'file' as blobs (fix #1118)

This commit is contained in:
Jakub Vrana
2025-09-07 13:44:00 +02:00
parent 2db30ba7e2
commit fc2ab7de16
6 changed files with 15 additions and 7 deletions

View File

@@ -21,6 +21,7 @@
- PostgreSQL: Quote edit value with interval operator
- PostgreSQL: Fix calling functions with name-less parameters
- PostgreSQL: Fix calling functions returing table
- PostgreSQL: Don't treat user types containing 'file' as blobs (bug #1118)
- PostgreSQL 11-: Avoid duplicate oid in table status (bug #1089)
- Elasticsearch: Support dropping aliases
- Plugins: Methods afterConnect(), processList() and killProcess()

View File

@@ -304,7 +304,7 @@ class Adminer {
: (preg_match('~json~', $field["type"]) ? "<code class='jush-js'>$val</code>"
: $val)
));
if (preg_match('~blob|bytea|raw|file~', $field["type"]) && !is_utf8($val)) {
if (is_blob($field) && !is_utf8($val)) {
$return = "<i>" . lang('%d byte(s)', strlen($original)) . "</i>";
}
return ($link ? "<a href='" . h($link) . "'" . (is_url($link) ? target_blank() : "") . ">$return</a>" : $return);
@@ -703,7 +703,7 @@ class Adminer {
}
}
}
if ($key && $functions && !preg_match('~set|blob|bytea|raw|file|bool~', $field["type"])) {
if ($key && $functions && !preg_match('~set|bool~', $field["type"]) && !is_blob($field)) {
$return .= "/SQL";
}
}
@@ -843,7 +843,7 @@ class Adminer {
}
}
}
$result = connection()->query($query, 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers
$result = connection()->query($query, 1); // 1 - MYSQLI_USE_RESULT
if ($result) {
$insert = "";
$buffer = "";

View File

@@ -791,6 +791,13 @@ function select_value($val, string $link, array $field, ?string $text_length): s
return adminer()->selectVal($return, $link, $field, $val);
}
/** Check whether the field type is blob or equivalent
* @param Field $field
*/
function is_blob(array $field): bool {
return preg_match('~blob|bytea|raw|file~', $field["type"]) && !in_array($field["type"], idx(driver()->structuredTypes(), lang('User types'), array()));
}
/** Check whether the string is e-mail address */
function is_mail(?string $email): bool {
$atom = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]'; // characters of local-name

View File

@@ -240,7 +240,7 @@ function input(array $field, $value, ?string $function, ?bool $autofocus = false
$checked = in_array($val, explode(",", $value), true);
echo " <label><input type='checkbox' name='fields[$name][$i]' value='" . h($val) . "'" . ($checked ? ' checked' : '') . ">" . h(adminer()->editVal($val, $field)) . '</label>';
}
} elseif (preg_match('~blob|bytea|raw|file~', $field["type"]) && ini_bool("file_uploads")) {
} elseif (is_blob($field) && ini_bool("file_uploads")) {
echo "<input type='file' name='fields-$name'>";
} elseif ($function == "json" || preg_match('~^jsonb?$~', $field["type"])) {
echo "<textarea$attrs cols='50' rows='12' class='jush-js'>" . h($value) . '</textarea>';
@@ -324,7 +324,7 @@ function process_input(array $field) {
}
return $value;
}
if (preg_match('~blob|bytea|raw|file~', $field["type"]) && ini_bool("file_uploads")) {
if (is_blob($field) && ini_bool("file_uploads")) {
$file = get_file("fields-$idf");
if (!is_string($file)) {
return false; //! report errors

View File

@@ -423,7 +423,7 @@ if (!$columns && support("table")) {
}
$link = "";
if (preg_match('~blob|bytea|raw|file~', $field["type"]) && $val != "") {
if (is_blob($field) && $val != "") {
$link = ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf;
}
if (!$link && $val !== null) { // link related items

View File

@@ -219,7 +219,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
function selectVal($val, $link, $field, $original) {
$return = $val;
$link = h($link);
if (preg_match('~blob|bytea~', $field["type"]) && !is_utf8($val)) {
if (is_blob($field) && !is_utf8($val)) {
$return = lang('%d byte(s)', strlen($original));
if (preg_match("~^(GIF|\xFF\xD8\xFF|\x89PNG\x0D\x0A\x1A\x0A)~", $original)) { // GIF|JPG|PNG, getimagetype() works with filename
$return = "<img src='$link' alt='$return'>";