Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit78bf0a2

Browse files
committed
hstore: Tighten key/value parsing check for whitespaces
isspace() can be locale-sensitive depending on the platform, causinghstore to consider as whitespaces characters it should not see as such.For example, U+0105, being decoded as 0xC4 0x85 in UTF-8, would bediscarded from the input given.This problem is similar to9ae2661, though it was missed that hstorecan also manipulate non-ASCII inputs, so replace the existing isspace()calls with scanner_isspace().This problem exists for a long time, so backpatch all the way down.Author: Evan JonesDiscussion:https://postgr.es/m/CA+HWA9awUW0+RV_gO9r1ABZwGoZxPztcJxPy8vMFSTbTfi4jig@mail.gmail.comBackpatch-through: 11
1 parent37236ca commit78bf0a2

File tree

5 files changed

+69
-5
lines changed

5 files changed

+69
-5
lines changed

‎contrib/hstore/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ PGFILEDESC = "hstore - key/value pair data type"
2020

2121
HEADERS = hstore.h
2222

23-
REGRESS = hstore
23+
REGRESS = hstore hstore_utf8
2424

2525
ifdefUSE_PGXS
2626
PG_CONFIG = pg_config
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This test must be run in a database with UTF-8 encoding,
3+
* because other encodings don't support all the characters used.
4+
*/
5+
SELECT getdatabaseencoding() <> 'UTF8'
6+
AS skip_test \gset
7+
\if :skip_test
8+
\quit
9+
\endif
10+
SET client_encoding = utf8;
11+
-- UTF-8 locale bug on macOS: isspace(0x85) returns true. \u0105 encodes
12+
-- as 0xc4 0x85 in UTF-8; the 0x85 was interpreted here as a whitespace.
13+
SELECT E'key\u0105=>value\u0105'::hstore;
14+
hstore
15+
------------------
16+
"keyą"=>"valueą"
17+
(1 row)
18+
19+
SELECT 'keyą=>valueą'::hstore;
20+
hstore
21+
------------------
22+
"keyą"=>"valueą"
23+
(1 row)
24+
25+
SELECT 'ą=>ą'::hstore;
26+
hstore
27+
----------
28+
"ą"=>"ą"
29+
(1 row)
30+
31+
SELECT 'keyąfoo=>valueą'::hstore;
32+
hstore
33+
---------------------
34+
"keyąfoo"=>"valueą"
35+
(1 row)
36+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* This test must be run in a database with UTF-8 encoding,
3+
* because other encodings don't support all the characters used.
4+
*/
5+
SELECT getdatabaseencoding() <> 'UTF8'
6+
AS skip_test \gset
7+
\if :skip_test
8+
\quit

‎contrib/hstore/hstore_io.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include"hstore.h"
1313
#include"lib/stringinfo.h"
1414
#include"libpq/pqformat.h"
15+
#include"parser/scansup.h"
1516
#include"utils/builtins.h"
1617
#include"utils/json.h"
1718
#include"utils/jsonb.h"
@@ -86,7 +87,7 @@ get_val(HSParser *state, bool ignoreeq, bool *escaped)
8687
{
8788
st=GV_WAITESCIN;
8889
}
89-
elseif (!isspace((unsignedchar)*(state->ptr)))
90+
elseif (!scanner_isspace((unsignedchar)*(state->ptr)))
9091
{
9192
*(state->cur)=*(state->ptr);
9293
state->cur++;
@@ -109,7 +110,7 @@ get_val(HSParser *state, bool ignoreeq, bool *escaped)
109110
state->ptr--;
110111
return true;
111112
}
112-
elseif (isspace((unsignedchar)*(state->ptr)))
113+
elseif (scanner_isspace((unsignedchar)*(state->ptr)))
113114
{
114115
return true;
115116
}
@@ -217,7 +218,7 @@ parse_hstore(HSParser *state)
217218
{
218219
elog(ERROR,"Unexpected end of string");
219220
}
220-
elseif (!isspace((unsignedchar)*(state->ptr)))
221+
elseif (!scanner_isspace((unsignedchar)*(state->ptr)))
221222
{
222223
elog(ERROR,"Syntax error near '%c' at position %d",*(state->ptr), (int32) (state->ptr-state->begin));
223224
}
@@ -265,7 +266,7 @@ parse_hstore(HSParser *state)
265266
{
266267
return;
267268
}
268-
elseif (!isspace((unsignedchar)*(state->ptr)))
269+
elseif (!scanner_isspace((unsignedchar)*(state->ptr)))
269270
{
270271
elog(ERROR,"Syntax error near '%c' at position %d",*(state->ptr), (int32) (state->ptr-state->begin));
271272
}

‎contrib/hstore/sql/hstore_utf8.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* This test must be run in a database with UTF-8 encoding,
3+
* because other encodings don't support all the characters used.
4+
*/
5+
6+
SELECT getdatabaseencoding()<>'UTF8'
7+
AS skip_test \gset
8+
\if :skip_test
9+
\quit
10+
\endif
11+
12+
SET client_encoding= utf8;
13+
14+
-- UTF-8 locale bug on macOS: isspace(0x85) returns true. \u0105 encodes
15+
-- as 0xc4 0x85 in UTF-8; the 0x85 was interpreted here as a whitespace.
16+
SELECT E'key\u0105=>value\u0105'::hstore;
17+
SELECT'keyą=>valueą'::hstore;
18+
SELECT'ą=>ą'::hstore;
19+
SELECT'keyąfoo=>valueą'::hstore;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp