babelfish-for-postgresql / babelfish_extensions

Babelfish for PostgreSQL provides the capability for PostgreSQL to work with applications written for Microsoft SQL Server. Babelfish understands the SQL Server wire-protocol and T-SQL, the Microsoft SQL Server query and procedural language, so you donโ€™t have to switch database drivers or rewrite all of your application queries.
https://babelfishpg.org/
Apache License 2.0
274 stars 93 forks source link

fix infinite loop in replace with AI collations #2867

Closed tanscorpio7 closed 1 month ago

tanscorpio7 commented 1 month ago

Description

Cherry Picked From : https://github.com/babelfish-for-postgresql/babelfish_extensions/pull/2849

ICU usearch_next() goes into infinite loop when pattern to search starts with a surrogate pair. To get around this we check if output of usearch_next() is stuck and not proceeding forwards and set the offset for next search ourselves. The next offset is simply the next character after the current char in source string.

SRC STRING - 'abc๐Ÿ™‚defghi๐Ÿ™‚๐Ÿ™‚'    PATTERN TO FIND = '๐Ÿ™‚def'

usearch_next() gets stuck on "๐Ÿ™‚" idx = 3 and repeatedly returns this index.
We will intervene and set the offset to "d" idx = 4. 
So that usearch_next only starts looking from this character.

Issues Resolved

[BABEL-5169]

Sign Off

Signed-off-by: Tanzeel Khan tzlkhan@amazon.com

Check List

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

coveralls commented 1 month ago

Pull Request Test Coverage Report for Build 10470060276

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
contrib/babelfishpg_tsql/src/collation.c 20 22 90.91%
<!-- Total: 20 22 90.91% -->
Totals Coverage Status
Change from base Build 10383172619: 0.005%
Covered Lines: 44198
Relevant Lines: 59983

๐Ÿ’› - Coveralls