diff --git a/conans/util/files.py b/conans/util/files.py
index 472fa854e..6ce2519ae 100644
--- a/conans/util/files.py
+++ b/conans/util/files.py
@@ -298,7 +298,7 @@ def tar_extract(fileobj, destination_dir):
         return not realpath(abspath(joinpath(base, path))).startswith(base)
 
     def safemembers(members):
-        base = realpath(abspath("."))
+        base = realpath(abspath(destination_dir))
 
         for finfo in members:
             if badpath(finfo.name, base) or finfo.islnk():

tar_extract is affected by symlinks in current directory
If a current directory has a symlink with the name matching a directory in the installed conan_package.tgz, then the directory is not extracted to the package directory.

Reproduced on 1.15.0-dev. Notice the `include` directory disappears from the package directory.
```
$ mkdir /tmp/testing && cd /tmp/testing
$ conan new Hello/0.1 -t
$ conan create . demo/testing
$ conan upload Hello/0.1@demo/testing --all
$ conan remove Hello/0.1@demo/testing --force
$ conan install Hello/0.1@demo/testing
$ conan get Hello/0.1@demo/testing:57547fe65fffc300f05aa42ee64b3b02eeabb6d7 .
Listing directory '.':
 conaninfo.txt
 conanmanifest.txt
 include
 lib
$ ln -s /tmp include
$ conan remove Hello/0.1@demo/testing --force
$ conan install Hello/0.1@demo/testing
$ conan get Hello/0.1@demo/testing:57547fe65fffc300f05aa42ee64b3b02eeabb6d7 .
Listing directory '.':
 conaninfo.txt
 conanmanifest.txt
 lib
```

The issue is caused by `badpath` check. The `base` is the current directory. Joining current directory and `include`, and resolving the symlink makes it to not to start with the current directory. What is the true intent for the `badpath` method? Is there a good test case to show it's necessary?
```python
  293 def tar_extract(fileobj, destination_dir):
  294     """Extract tar file controlling not absolute paths and fixing the routes
  295     if the tar was zipped in windows"""
  296     def badpath(path, base):
  297         # joinpath will ignore base if path is absolute
  298         return not realpath(abspath(joinpath(base, path))).startswith(base)
  299
  300     def safemembers(members):
  301         base = realpath(abspath("."))
  302
  303         for finfo in members:
  304             if badpath(finfo.name, base) or finfo.islnk():
  305                 continue
  306             else:
  307                 # Fixes unzip a windows zipped file in linux
  308                 finfo.name = finfo.name.replace("\\", "/")
  309                 yield finfo
```




- [x] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [x] I've specified the Conan version, operating system version and any tool that can be relevant.
- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.


diff --git a/conans/test/unittests/util/files/tar_extract_test.py b/conans/test/unittests/util/files/tar_extract_test.py
new file mode 100644
index 000000000..98fa013a5
--- /dev/null
+++ b/conans/test/unittests/util/files/tar_extract_test.py
@@ -0,0 +1,63 @@
+# coding=utf-8
+
+import os
+import platform
+import tarfile
+import unittest
+
+from conans.client.tools.files import chdir
+from conans.model.manifest import gather_files
+from conans.test.utils.test_files import temp_folder
+from conans.util.files import tar_extract, gzopen_without_timestamps, save
+
+
+class TarExtractTest(unittest.TestCase):
+
+    def setUp(self):
+        self.tmp_folder = temp_folder()
+        with chdir(self.tmp_folder):
+            # Create a couple of files
+            ori_files_dir = os.path.join(self.tmp_folder, "ori")
+            file1 = os.path.join(ori_files_dir, "file1")
+            file2 = os.path.join(ori_files_dir, "folder", "file2")
+            save(file1, "")
+            save(file2, "")
+
+            # Create a tar.gz file with the above files
+            self.tgz_file = os.path.join(self.tmp_folder, "file.tar.gz")
+            with open(self.tgz_file, "wb") as tgz_handle:
+                tgz = gzopen_without_timestamps("name", mode="w", fileobj=tgz_handle)
+
+                files, _ = gather_files(ori_files_dir)
+                for filename, abs_path in files.items():
+                    info = tarfile.TarInfo(name=filename)
+                    with open(file1, 'rb') as file_handler:
+                        tgz.addfile(tarinfo=info, fileobj=file_handler)
+                tgz.close()
+
+    @unittest.skipUnless(platform.system() == "Linux", "Requires Linux")
+    def test_link_folder(self):
+        # If there is a linked folder in the current directory that matches one file in the tar.
+        # https://github.com/conan-io/conan/issues/4959
+
+        # Once unpackaged, this is the content of the destination directory
+        def check_files(destination_dir):
+            d = os.listdir(destination_dir)
+            self.assertListEqual(d, ["folder", "file1"])
+            d_folder = os.listdir(os.path.join(destination_dir, "folder"))
+            self.assertEqual(d_folder, ["file2"])
+
+        working_dir = temp_folder()
+        with chdir(working_dir):
+            # Unpack and check
+            destination_dir = os.path.join(self.tmp_folder, "dest")
+            with open(self.tgz_file, 'rb') as file_handler:
+                tar_extract(file_handler, destination_dir)
+            check_files(destination_dir)
+
+            # Unpack and check (now we have a symlinked local folder)
+            os.symlink(temp_folder(), "folder")
+            destination_dir = os.path.join(self.tmp_folder, "dest2")
+            with open(self.tgz_file, 'rb') as file_handler:
+                tar_extract(file_handler, destination_dir)
+            check_files(destination_dir)

pip install -e .[dev]
parse_log_pytest
requirements.txt
nose nose-cov pytest
apt-get update apt-get install -y gcc g++-multilib wget unzip pip3 install meson
3.9
conans/requirements.txt conans/requirements_server.txt conans/requirements_dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
astroid==3.3.9
beautifulsoup4==4.13.3
bottle==0.12.25
certifi==2025.1.31
charset-normalizer==3.4.1
codecov==2.1.13
colorama==0.4.6
-e git+https://github.com/conan-io/conan.git@556e2043e11bc53d6ad797519385b9b34dfdbb2d#egg=conan
cov-core==1.15.0
coverage==4.2
deprecation==2.0.7
dill==0.3.9
distro==1.1.0
exceptiongroup==1.2.2
fasteners==0.19
future==0.16.0
idna==3.10
iniconfig==2.1.0
isort==6.0.1
Jinja2==2.11.3
MarkupSafe==3.0.2
mccabe==0.7.0
meson==1.7.0
mock==1.3.0
node-semver==0.6.1
nose==1.3.7
nose-cov==1.6
packaging==24.2
parameterized==0.9.0
patch==1.16
pbr==6.1.1
platformdirs==4.3.7
pluggy==1.5.0
pluginbase==0.7
Pygments==2.19.1
PyJWT==1.7.1
pylint==3.3.6
pytest==8.3.5
PyYAML==3.13
requests==2.32.3
six==1.17.0
soupsieve==2.6
tomli==2.2.1
tomlkit==0.13.2
tqdm==4.67.1
typing_extensions==4.13.0
urllib3==2.3.0
waitress==3.0.2
WebOb==1.8.9
WebTest==2.0.35

name: conan
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - astroid==3.3.9
      - beautifulsoup4==4.13.3
      - bottle==0.12.25
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - codecov==2.1.13
      - colorama==0.4.6
      - cov-core==1.15.0
      - coverage==4.2
      - deprecation==2.0.7
      - dill==0.3.9
      - distro==1.1.0
      - exceptiongroup==1.2.2
      - fasteners==0.19
      - future==0.16.0
      - idna==3.10
      - iniconfig==2.1.0
      - isort==6.0.1
      - jinja2==2.11.3
      - markupsafe==3.0.2
      - mccabe==0.7.0
      - meson==1.7.0
      - mock==1.3.0
      - node-semver==0.6.1
      - nose==1.3.7
      - nose-cov==1.6
      - packaging==24.2
      - parameterized==0.9.0
      - patch==1.16
      - pbr==6.1.1
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - pluginbase==0.7
      - pygments==2.19.1
      - pyjwt==1.7.1
      - pylint==3.3.6
      - pytest==8.3.5
      - pyyaml==3.13
      - requests==2.32.3
      - six==1.17.0
      - soupsieve==2.6
      - tomli==2.2.1
      - tomlkit==0.13.2
      - tqdm==4.67.1
      - typing-extensions==4.13.0
      - urllib3==2.3.0
      - waitress==3.0.2
      - webob==1.8.9
      - webtest==2.0.35
prefix: /opt/conda/envs/conan

conans/test/unittests/util/files/tar_extract_test.py::TarExtractTest::test_link_folder
conans/util/files.py
conans/util/files.py