Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wteWu-000974-2c for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Aug 2026 04:56:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wteWr-0017l9-2Q for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Aug 2026 04:55:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wsKm0-009RI6-0j for pgsql-bugs@lists.postgresql.org; Fri, 07 Aug 2026 13:38:07 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wsKlx-00000000l1I-2xnh for pgsql-bugs@lists.postgresql.org; Fri, 07 Aug 2026 13:38:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=/YaWTGyblJqSzbVUpahILXVxtM0y4hZGU53o6NLKBjU=; b=4Xz5sNL/sdsBjbhL+YHkGWja+g i1mWn4a72s4aUR7T65kAJ5UHEtxUTC54ulP0Pv7QWpPtEo5fwoJKSHrOMNc55xalkVGGZT6tPDtR/ aVACdkmN+VbkkvsuofE7yte+eBHfG2wWrvHjiZnXYfJUZz2yHV5nBTfb5vCy+4MrlZAO2glHaAkPr sdvgoAOtxlL7M19iBpK9gshp/zqRHznZm1ELhAWEZvPZa3qKL8I6XVv7pCVGc4IAUKUl71bvg0fRs x2A6JwWcpYoNFJXa1FWfwNg3mYzd4a5bXgayOgjXB0Z0zlcUeSc/Bmiwnhvej4SMapbLLn+FYMoht Lz8XhjNA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wsKlw-000WkG-1P for pgsql-bugs@lists.postgresql.org; Fri, 07 Aug 2026 13:38:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1wsKlv-00000005HJH-1Bol for pgsql-bugs@lists.postgresql.org; Fri, 07 Aug 2026 13:38:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19613: pg_restore: several SEGVs in ReadToc() in pg_backup_archiver.c To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: ilia.kashintsev@gmail.com Reply-To: ilia.kashintsev@gmail.com, pgsql-bugs@lists.postgresql.org Date: Fri, 07 Aug 2026 13:37:25 +0000 Message-ID: <19613-3a9ffc23ee402382@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19613 Logged by: Ilia Kashintsev Email address: ilia.kashintsev@gmail.com PostgreSQL version: 19beta2 Operating system: Ubuntu 24.04.4 LTS Description: =20 Hello maintainers! I have found several SEGVs on unknown address in ReadToc(). They occur because return value of numerous ReadStr(AH) calls is never checked, with sscanf() or strcmp() being called on tmp =3D=3D NULL. For example pg_backup_archiver:2738-2739: tmp =3D ReadStr(AH); sscanf(tmp, "%u", &te->catalogId.tableoid); <------ Steps to reproduce: 1) Build the project with ASAN; sudo mkdir -p /builds2 sudo chown "$(whoami)" /builds2 mkdir -p asan_build cd asan_build export CC=3Dclang export CXX=3Dclang++ export CFLAGS=3D"-O1 -g -fsanitize=3Daddress -fno-omit-frame-pointer" export CXXFLAGS=3D"-O1 -g -fsanitize=3Daddress -fno-omit-frame-pointer" export LDFLAGS=3D"-fsanitize=3Daddress" ../postgres/configure --prefix=3D/builds2/pg-asan make -j sudo make install 2) Run the example: echo 'UEdETVABDDABMAEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwADAAMDAwMDA=3D' | base64 = -d > inp.bin /builds2/pg-asan/bin/pg_restore -f dump.sql inp.bin Sanitizer output: AddressSanitizer:DEADLYSIGNAL =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D247028=3D=3DERROR: AddressSanitizer: SEGV on unknown address 0x000000= 000000 (pc 0x778e90f7995d bp 0x7ffe3361c840 sp 0x7ffe3361c818 T0) =3D=3D247028=3D=3DThe signal is caused by a READ memory access. =3D=3D247028=3D=3DHint: address points to the zero page. #0 0x778e90f7995d in __strlen_avx2 string/../sysdeps/x86_64/multiarch/strlen-avx2.S:76 #1 0x778e90e853d4 in _IO_str_init_static_internal libio/strops.c:41:11 #2 0x778e90e4dd10 in _IO_strfile_read stdio-common/../libio/strfile.h:90:3 #3 0x778e90e4dd10 in __isoc23_vsscanf stdio-common/isoc23_vsscanf.c:24:13 #4 0x62420175134d in __isoc23_sscanf (/builds2/pg-asan/bin/pg_restore+0x6734d) (BuildId: b947abf32a751f35042d5aa2948e2318357a75a0) #5 0x62420182553e in ReadToc /home/reproduce/asan_build/../postgres/src/bin/pg_dump/pg_backup_archiver.c= :2739:4 #6 0x62420182c929 in InitArchiveFmt_Custom /home/reproduce/asan_build/../postgres/src/bin/pg_dump/pg_backup_custom.c:1= 80:3 #7 0x6242018164f1 in _allocAH /home/reproduce/asan_build/../postgres/src/bin/pg_dump/pg_backup_archiver.c= :2470:4 #8 0x624201816b1e in OpenArchive /home/reproduce/asan_build/../postgres/src/bin/pg_dump/pg_backup_archiver.c= :254:7 #9 0x624201807641 in main /home/reproduce/asan_build/../postgres/src/bin/pg_dump/pg_restore.c:488:7 #10 0x778e90e181c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #11 0x778e90e1828a in __libc_start_main csu/../csu/libc-start.c:360:3 #12 0x62420172c984 in _start (/builds2/pg-asan/bin/pg_restore+0x42984) (BuildId: b947abf32a751f35042d5aa2948e2318357a75a0) AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV string/../sysdeps/x86_64/multiarch/strlen-avx2.S:76 in __strlen_avx2 =3D=3D247028=3D=3DABORTING Suggested fix: Checking the return value of ReadStr resolves the issue. diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index d7da3fc..3e9ac90 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -2736,18 +2736,26 @@ ReadToc(ArchiveHandle *AH) if (AH->version >=3D K_VERS_1_8) { tmp =3D ReadStr(AH); + if (tmp =3D=3D NULL) + pg_fatal("corrupt TOC: missing tableoid"); sscanf(tmp, "%u", &te->catalogId.tableoid); free(tmp); } else te->catalogId.tableoid =3D InvalidOid; tmp =3D ReadStr(AH); + if (tmp =3D=3D NULL) + pg_fatal("corrupt TOC: missing oid"); sscanf(tmp, "%u", &te->catalogId.oid); free(tmp); te->tag =3D ReadStr(AH); - te->desc =3D ReadStr(AH); + if (te->tag =3D=3D NULL) + pg_fatal("corrupt TOC: missing entry tag"); + te->desc =3D ReadStr(AH); + if (te->desc =3D=3D NULL) + pg_fatal("corrupt TOC: missing entry description"); if (AH->version >=3D K_VERS_1_11) { te->section =3D ReadInt(AH); @@ -2804,6 +2812,8 @@ ReadToc(ArchiveHandle *AH) { tmp =3D ReadStr(AH); + if (tmp =3D=3D NULL) + pg_fatal("corrupt TOC: missing WITH OIDS marker"); if (strcmp(tmp, "true") =3D=3D 0) is_supported =3D false;