1. 16 Aug, 2022 3 commits
  2. 15 Aug, 2022 2 commits
  3. 14 Aug, 2022 1 commit
    • Tom Lane's avatar
      Preserve memory context of VarStringSortSupport buffers. · 06602372
      Tom Lane authored
      When enlarging the work buffers of a VarStringSortSupport object,
      varstrfastcmp_locale was careful to keep them in the ssup_cxt
      memory context; but varstr_abbrev_convert just used palloc().
      The latter creates a hazard that the buffers could be freed out
      from under the VarStringSortSupport object, resulting in stomping
      on whatever gets allocated in that memory later.
      
      In practice, because we only use this code for ICU collations
      (cf. 3df9c374), the problem is confined to use of ICU collations.
      I believe it may have been unreachable before the introduction
      of incremental sort, too, as traditional sorting usually just
      uses one context for the duration of the sort.
      
      We could fix this by making the broken stanzas in varstr_abbrev_convert
      match the non-broken ones in varstrfastcmp_locale.  However, it seems
      like a better idea to dodge the issue altogether by replacing the
      pfree-and-allocate-anew coding with repalloc, which automatically
      preserves the chunk's memory context.  This fix does add a few cycles
      because repalloc will copy the chunk's content, which the existing
      coding assumes is useless.  However, we don't expect that these buffer
      enlargement operations are performance-critical.  Besides that, it's
      far from obvious that copying the buffer contents isn't required, since
      these stanzas make no effort to mark the buffers invalid by resetting
      last_returned, cache_blob, etc.  That seems to be safe upon examination,
      but it's fragile and could easily get broken in future, which wouldn't
      get revealed in testing with short-to-moderate-size strings.
      
      Per bug #17584 from James Inform.  Whether or not the issue is
      reachable in the older branches, this code has been broken on its
      own terms from its introduction, so patch all the way back.
      
      Discussion: https://postgr.es/m/17584-95c79b4a7d771f44@postgresql.org
      06602372
  4. 13 Aug, 2022 3 commits
    • Tom Lane's avatar
      Avoid misbehavior when hash_table_bytes < bucket_size. · 1dfc9193
      Tom Lane authored
      It's possible to reach this case when work_mem is very small and tupsize
      is (relatively) very large.  In that case ExecChooseHashTableSize would
      get an assertion failure, or with asserts off it'd compute nbuckets = 0,
      which'd likely cause misbehavior later (I've not checked).  To fix,
      clamp the number of buckets to be at least 1.
      
      This is due to faulty conversion of old my_log2() coding in 28d936031.
      Back-patch to v13, as that was.
      
      Zhang Mingli
      
      Discussion: https://postgr.es/m/beb64ca0-91e2-44ac-bf4a-7ea36275ec02@Spark
      1dfc9193
    • Tom Lane's avatar
      Catch stack overflow when recursing in transformFromClauseItem(). · 496ab1d6
      Tom Lane authored
      Most parts of the parser can expect that the stack overflow check
      in transformExprRecurse() will trigger before things get desperate.
      However, transformFromClauseItem() can recurse directly to self
      without having analyzed any expressions, so it's possible to drive
      it to a stack-overrun crash.  Add a check to prevent that.
      
      Per bug #17583 from Egor Chindyaskin.  Back-patch to all supported
      branches.
      
      Richard Guo
      
      Discussion: https://postgr.es/m/17583-33be55b9f981f75c@postgresql.org
      496ab1d6
    • Peter Eisentraut's avatar
      Add missing fields to _outConstraint() · 2db574a2
      Peter Eisentraut authored
      As of 89779524, check constraints can
      be declared invalid.  But that patch didn't update _outConstraint() to
      also show the relevant struct fields (which were only applicable to
      foreign keys before that).  This currently only affects debugging
      output, so no impact in practice.
      2db574a2
  5. 12 Aug, 2022 11 commits
  6. 11 Aug, 2022 1 commit
    • Amit Kapila's avatar
      Fix catalog lookup with the wrong snapshot during logical decoding. · 68dcce24
      Amit Kapila authored
      Previously, we relied on HEAP2_NEW_CID records and XACT_INVALIDATION
      records to know if the transaction has modified the catalog, and that
      information is not serialized to snapshot. Therefore, after the restart,
      if the logical decoding decodes only the commit record of the transaction
      that has actually modified a catalog, we will miss adding its XID to the
      snapshot. Thus, we will end up looking at catalogs with the wrong
      snapshot.
      
      To fix this problem, this changes the snapshot builder so that it
      remembers the last-running-xacts list of the decoded RUNNING_XACTS record
      after restoring the previously serialized snapshot. Then, we mark the
      transaction as containing catalog changes if it's in the list of initial
      running transactions and its commit record has XACT_XINFO_HAS_INVALS. To
      avoid ABI breakage, we store the array of the initial running transactions
      in the static variables InitialRunningXacts and NInitialRunningXacts,
      instead of storing those in SnapBuild or ReorderBuffer.
      
      This approach has a false positive; we could end up adding the transaction
      that didn't change catalog to the snapshot since we cannot distinguish
      whether the transaction has catalog changes only by checking the COMMIT
      record. It doesn't have the information on which (sub) transaction has
      catalog changes, and XACT_XINFO_HAS_INVALS doesn't necessarily indicate
      that the transaction has catalog change. But that won't be a problem since
      we use snapshot built during decoding only to read system catalogs.
      
      On the master branch, we took a more future-proof approach by writing
      catalog modifying transactions to the serialized snapshot which avoids the
      above false positive. But we cannot backpatch it because of a change in
      the SnapBuild.
      
      Reported-by: Mike Oh
      Author: Masahiko Sawada
      Reviewed-by: Amit Kapila, Shi yu, Takamichi Osumi, Kyotaro Horiguchi, Bertrand Drouvot, Ahsan Hadi
      Backpatch-through: 10
      Discussion: https://postgr.es/m/81D0D8B0-E7C4-4999-B616-1E5004DBDCD2%40amazon.com
      68dcce24
  7. 10 Aug, 2022 1 commit
  8. 08 Aug, 2022 5 commits
    • Tom Lane's avatar
      Stamp 14.5. · 278273cc
      Tom Lane authored
      278273cc
    • Tom Lane's avatar
      Stabilize output of new regression test. · c0d5d52a
      Tom Lane authored
      Per buildfarm, the output order of \dx+ isn't consistent across
      locales.  Apply NO_LOCALE to force C locale.  There might be a
      more localized way, but I'm not seeing it offhand, and anyway
      there is nothing in this test module that particularly cares
      about locales.
      
      Security: CVE-2022-2625
      c0d5d52a
    • Tom Lane's avatar
      Last-minute updates for release notes. · ea2917ca
      Tom Lane authored
      Security: CVE-2022-2625
      ea2917ca
    • Tom Lane's avatar
      In extensions, don't replace objects not belonging to the extension. · 5721da7e
      Tom Lane authored
      Previously, if an extension script did CREATE OR REPLACE and there was
      an existing object not belonging to the extension, it would overwrite
      the object and adopt it into the extension.  This is problematic, first
      because the overwrite is probably unintentional, and second because we
      didn't change the object's ownership.  Thus a hostile user could create
      an object in advance of an expected CREATE EXTENSION command, and would
      then have ownership rights on an extension object, which could be
      modified for trojan-horse-type attacks.
      
      Hence, forbid CREATE OR REPLACE of an existing object unless it already
      belongs to the extension.  (Note that we've always forbidden replacing
      an object that belongs to some other extension; only the behavior for
      previously-free-standing objects changes here.)
      
      For the same reason, also fail CREATE IF NOT EXISTS when there is
      an existing object that doesn't belong to the extension.
      
      Our thanks to Sven Klemm for reporting this problem.
      
      Security: CVE-2022-2625
      5721da7e
    • Alvaro Herrera's avatar
      Translation updates · 9a8df330
      Alvaro Herrera authored
      Source-Git-URL: ssh://git@git.postgresql.org/pgtranslation/messages.git
      Source-Git-Hash: 20d70fc4a9763d5d31afc422be0be0feb0fb0363
      9a8df330
  9. 07 Aug, 2022 2 commits
  10. 06 Aug, 2022 1 commit
    • Alvaro Herrera's avatar
      Improve recently-added test reliability · 9d5c96d9
      Alvaro Herrera authored
      Commit 59be1c942a47 already tried to make
      src/test/recovery/t/033_replay_tsp_drops more reliable, but it wasn't
      enough.  Try to improve on that by making this use of a replication slot
      to be more like others.  Also, don't drop the slot.
      
      Make a few other stylistic changes while at it.  It's still quite slow,
      which is another thing that we need to fix in this script.
      
      Backpatch to all supported branches.
      
      Discussion: https://postgr.es/m/349302.1659191875@sss.pgh.pa.us
      9d5c96d9
  11. 05 Aug, 2022 10 commits
    • Tom Lane's avatar
      First-draft release notes for 14.5. · aab05919
      Tom Lane authored
      As usual, the release notes for older branches will be made by cutting
      these down, but put them up for community review first.
      
      Due to the out-of-cycle release of 14.4, there are a number of commits
      that appeared in 14.4 that are not yet shipped in the earlier branches.
      This draft repeats those release note entries for convenience in
      preparing the older-branch notes later.  They'll be stripped out of
      the 14.5 section after that's done.
      aab05919
    • Tom Lane's avatar
      Partially undo commit 94da73281. · b9243cad
      Tom Lane authored
      On closer inspection, mcv.c isn't as broken for ScalarArrayOpExpr
      as I thought.  The Var-on-right issue is real enough, but actually
      it does cope fine with a NULL array constant --- I was misled by
      an XXX comment suggesting it didn't.  Undo that part of the code
      change, and replace the XXX comment with something less misleading.
      b9243cad
    • Tom Lane's avatar
      Fix handling of bare boolean expressions in mcv_get_match_bitmap. · 3fe2fc6b
      Tom Lane authored
      Since v14, the extended stats machinery will try to estimate for
      otherwise-unsupported boolean expressions if they match an expression
      available from an extended stats object.  mcv.c did not get the memo
      about this, and would spit up with "unknown clause type".  Fortunately
      the case is easy to handle, since we can expect the expression yields
      boolean.
      
      While here, replace some not-terribly-on-point assertions with
      simpler runtime tests for lookup failure.  That seems appropriate
      so that we get an elog not a crash if we somehow get to the new
      it-should-be-a-bool-expression code with a subexpression that
      doesn't match any stats column.
      
      Per report from Danny Shemesh.  Thanks to Justin Pryzby for
      preliminary investigation.
      
      Discussion: https://postgr.es/m/CAFZC=QqD6=27wQPOW1pbRa98KPyuyn+7cL_Ay_Ck-roZV84vHg@mail.gmail.com
      3fe2fc6b
    • Tom Lane's avatar
      Fix non-bulletproof ScalarArrayOpExpr code for extended statistics. · ea6c9169
      Tom Lane authored
      statext_is_compatible_clause_internal() checked that the arguments
      of a ScalarArrayOpExpr are one Var and one Const, but it would allow
      cases where the Const was on the left.  Subsequent uses of the clause
      are not expecting that and would suffer assertion failures or core
      dumps.  mcv.c also had not bothered to cope with the case of a NULL
      array constant, which seems really unacceptably sloppy of somebody.
      (Although our tools failed us there too, since AFAIK neither Coverity
      nor any compiler warned of the obvious use-of-uninitialized-variable
      condition.)  It seems best to handle that by having
      statext_is_compatible_clause_internal() reject it.
      
      Noted while fixing bug #17570.  Back-patch to v13 where the
      extended stats code grew some awareness of ScalarArrayOpExpr.
      ea6c9169
    • Alvaro Herrera's avatar
      Backpatch addition of .git-blame-ignore-revs · fff3f333
      Alvaro Herrera authored
      This makes it more convenient for git config to contain the
      blame.ignoreRevsFile setting; otherwise current git versions complain if
      the file is not present.
      
      I constructed the file for each branch by scraping the file in branch
      master for commits that appear in that branch.  Because a few additional
      pgindent commits have been added to the list in master since the list
      was first created, this also propagates those to branches 14 and 15
      where the file already existed.  Also, some entries appear to have been
      made using author-date rather than committer-date in the format string,
      so some timestamps are changed.  Also remove bogus whitespace in the
      suggested `git log` format string.
      
      Backpatch to all supported branches.
      
      Discussion: https://postgr.es/m/20220711163138.o72evdeus5f5yy5z@alvherre.pgsql
      fff3f333
    • Tom Lane's avatar
      Fix incorrect permissions-checking code for extended statistics. · 7c6ce047
      Tom Lane authored
      Commit a4d75c86 improved the extended-stats logic to allow extended
      stats to be collected on expressions not just bare Vars.  To apply
      such stats, we first verify that the user has permissions to read all
      columns used in the stats.  (If not, the query will likely fail at
      runtime, but the planner ought not do so.)  That had to get extended
      to check permissions of columns appearing within such expressions,
      but the code for that was completely wrong: it applied pull_varattnos
      to the wrong pointer, leading to "unrecognized node type" failures.
      Furthermore, although you couldn't get to this because of that bug,
      it failed to account for the attnum offset applied by pull_varattnos.
      
      This escaped recognition so far because the code in question is not
      reached when the user has whole-table SELECT privilege (which is the
      common case), and because only subexpressions not specially handled
      by statext_is_compatible_clause_internal() are at risk.
      
      I think a large part of the reason for this bug is under-documentation
      of what statext_is_compatible_clause() is doing and what its arguments
      are, so do some work on the comments to try to improve that.
      
      Per bug #17570 from Alexander Kozhemyakin.  Patch by Richard Guo;
      comments and other cosmetic improvements by me.  (Thanks also to
      Japin Li for diagnosis.)  Back-patch to v14 where the bug came in.
      
      Discussion: https://postgr.es/m/17570-f2f2e0f4bccf0965@postgresql.org
      7c6ce047
    • Alvaro Herrera's avatar
      BRIN: mask BRIN_EVACUATE_PAGE for WAL consistency checking · 541f41d4
      Alvaro Herrera authored
      That bit is unlogged and therefore it's wrong to consider it in WAL page
      comparison.
      
      Add a test that tickles the case, as branch testing technology allows.
      
      This has been a problem ever since wal consistency checking was
      introduced (commit a507b869 for pg10), so backpatch to all supported
      branches.
      
      Author: 王海洋 (Haiyang Wang) <wanghaiyang.001@bytedance.com>
      Reviewed-by: default avatarKyotaro Horiguchi <horikyota.ntt@gmail.com>
      Discussion: https://postgr.es/m/CACciXAD2UvLMOhc4jX9VvOKt7DtYLr3OYRBhvOZ-jRxtzc_7Jg@mail.gmail.com
      Discussion: https://postgr.es/m/CACciXADOfErX9Bx0nzE_SkdfXr6Bbpo5R=v_B6MUTEYW4ya+cg@mail.gmail.com
      541f41d4
    • Noah Misch's avatar
      Add HINT for restartpoint race with KeepFileRestoredFromArchive(). · 8ad6c5db
      Noah Misch authored
      The five commits ending at cc2c7d65fc27e877c9f407587b0b92d46cd6dd16
      closed this race condition for v15+.  For v14 through v10, add a HINT to
      discourage studying the cosmetic problem.
      
      Reviewed by Kyotaro Horiguchi and David Steele.
      
      Discussion: https://postgr.es/m/20220731061747.GA3692882@rfd.leadboat.com
      8ad6c5db
    • Alvaro Herrera's avatar
      regress: fix test instability · 6d9481cd
      Alvaro Herrera authored
      Having additional triggers in a test table made the ORDER BY clauses in
      old queries underspecified.  Add another column there for stability.
      
      Per sporadic buildfarm pink.
      6d9481cd
    • Etsuro Fujita's avatar
      postgres_fdw: Disable batch insertion when there are WCO constraints. · 4a9bc2e0
      Etsuro Fujita authored
      When inserting a view referencing a foreign table that has WITH CHECK
      OPTION constraints, in single-insert mode postgres_fdw retrieves the
      data that was actually inserted on the remote side so that the WITH
      CHECK OPTION constraints are enforced with the data locally, but in
      batch-insert mode it cannot currently retrieve the data (except for the
      row first inserted through the view), resulting in enforcing the WITH
      CHECK OPTION constraints with the data passed from the core (except for
      the first-inserted row), which led to incorrect results when inserting
      into a view referencing a foreign table in which a remote BEFORE ROW
      INSERT trigger changes the rows inserted through the view so that they
      violate the view's WITH CHECK OPTION constraint.  Also, the query
      inserting into the view caused an assertion failure in assert-enabled
      builds.
      
      Fix these by disabling batch insertion when inserting into such a view.
      
      Back-patch to v14 where batch insertion was added.
      
      Discussion: https://postgr.es/m/CAPmGK17LpbTZs4m4a_6THP54UBeK9fHvX8aVVA%2BC6yEZDZwQcg%40mail.gmail.com
      4a9bc2e0