fix(supabase): V1-2.1 bound printed numbers before the size measure
check_document_structure sums the numbers' printed digits one at a time before building the whole text, so huge exponents answer document.too_large instead of an out-of-memory error. pgTAP 020: the full AR-1 B matrix and the rights RPCs refused to every non-owner; 017: exponent vectors, the number bomb, publish.species.other alone.
This commit is contained in:
1 parent
12816671e4
commit
3eba6d89b2
4 files changed
+198
-3
No files matched your search
@@ -8,7 +8,7 @@
|
||||
-- ids created here, so the file also runs on a stack that already holds
|
||||
-- sheets, rounds or a working copy.
|
||||
begin;
|
||||
select plan(104);
|
||||
select plan(110);
|
||||
|
||||
-- Accounts: O owner, E admin + editor + publisher, V reviewer, V2 admin +
|
||||
-- editor + reviewer (an author of a later round), V3 reviewer, R reader.
|
||||
@@ -604,6 +604,19 @@ select pg_temp.fixture_round('o2', 'o2.f', 'c',
|
||||
select throws_ok($$ select public.publish_sheet_version(pg_temp.id('o2.f')) $$,
|
||||
'P0001', 'publish.approval.invalid', 'M6: publication refused after an approval by an author (the owner)');
|
||||
|
||||
-- ============ Publication refused for the species `other` alone (§6.7) ============
|
||||
-- No RPC creates such a sheet (`sheet.species_invalid`); a row moved to `other`
|
||||
-- by the table owner after an otherwise valid approval stands in for it.
|
||||
select pg_temp.sheet('so', repeat('b6', 32));
|
||||
select pg_temp.fixture_round('so', 'so.f', 'd', jsonb_set(pg_temp.doc(pg_temp.id('so.asset'), 'reviewed'), '{description,fr}', '"so"'), 'E', 'V', 'V');
|
||||
reset role;
|
||||
alter table public.anatomical_sheets disable trigger user;
|
||||
update public.anatomical_sheets set species_id = 'other' where id = pg_temp.id('so');
|
||||
alter table public.anatomical_sheets enable trigger user;
|
||||
select pg_temp.as_user('E');
|
||||
select throws_ok($$ select public.publish_sheet_version(pg_temp.id('so.f')) $$,
|
||||
'P0001', 'publish.species.other', 'publication refused for the species other, every other rule met');
|
||||
|
||||
-- ============ Document size: UTF-8 bytes of the JSON text (§6.2, §12.2) ============
|
||||
select pg_temp.sheet('sz', repeat('c3', 32));
|
||||
select lives_ok($$ select pg_temp.save_now('sz', pg_temp.sized(pg_temp.doc(pg_temp.id('sz.asset'), 'reviewed'), 2097151, 'x')) $$,
|
||||
@@ -650,6 +663,26 @@ select ok((select octet_length(content::text) <= 2097152 and jsonb_array_length(
|
||||
select pg_temp.as_user('E');
|
||||
select throws_ok($$ select public.create_official_sheet('r17-szbig', pg_temp.sized(pg_temp.doc(null, 'reviewed'), 2097153, 'x')) $$,
|
||||
'23514', 'document.too_large', 'size: creation refuses a document of cap + 1 bytes with the closed code');
|
||||
-- Numbers count as PostgreSQL prints them: plain digits, never an exponent.
|
||||
select lives_ok($$ select pg_temp.save_now('sz', jsonb_set(pg_temp.doc(pg_temp.id('sz.asset'), 'reviewed'), '{pad}', '[1e-7, 1e21]')) $$,
|
||||
'size: numbers that JavaScript prints with an exponent are saved');
|
||||
reset role;
|
||||
select is((select content -> 'pad' #>> '{}' from public.anatomical_sheet_versions where id = pg_temp.id('sz.v')),
|
||||
'[0.0000001, 1000000000000000000000]', 'size: they are measured in their plain form');
|
||||
create table pg_temp.sz_exp as select jsonb_set(pg_temp.doc(pg_temp.id('sz.asset'), 'reviewed'), '{pad}',
|
||||
(select jsonb_agg(1e21) from generate_series(1, 100000))) as d;
|
||||
grant select on pg_temp.sz_exp to authenticated;
|
||||
select ok((select octet_length(replace(replace(d::text, ', ', ','), ': ', ':')) - 17 * 100000 <= 2097152
|
||||
and octet_length(d::text) > 2097152 from pg_temp.sz_exp),
|
||||
'size: the exponent fixture is under the cap in compact JavaScript form and over it as measured');
|
||||
select pg_temp.as_user('E');
|
||||
select throws_ok($$ select pg_temp.save_now('sz', (select d from pg_temp.sz_exp)) $$,
|
||||
'23514', 'document.too_large', 'size: a document over the cap only once its numbers print in full is refused');
|
||||
-- 9 000 numbers of 131 072 digits each: a 90 kB payload whose text would be
|
||||
-- 1.2 GB. The closed code comes back, not an out-of-memory error.
|
||||
select throws_ok($$ select pg_temp.save_now('sz', jsonb_set(pg_temp.doc(pg_temp.id('sz.asset'), 'reviewed'), '{pad}',
|
||||
(select jsonb_agg(1e131071) from generate_series(1, 9000)))) $$,
|
||||
'23514', 'document.too_large', 'size: numbers that print as gigabytes of digits get the closed code, not an out-of-memory error');
|
||||
reset role;
|
||||
select is((select pg_get_constraintdef(oid) from pg_constraint where conname = 'anatomical_sheet_versions_content_size'),
|
||||
'CHECK ((octet_length((content)::text) <= 2097152))',
|
||||
|
||||
Reference in new issue
Block a user