diff --git a/SOURCES/0002-testcase_read-error-out-if-repos-are-added-or-the-system-is-changed-too-late.patch b/SOURCES/0002-testcase_read-error-out-if-repos-are-added-or-the-system-is-changed-too-late.patch
new file mode 100644
index 0000000..a7efb4f
--- /dev/null
+++ b/SOURCES/0002-testcase_read-error-out-if-repos-are-added-or-the-system-is-changed-too-late.patch
@@ -0,0 +1,62 @@
+From 0956e7d1b1354860ab0bf7105c4477cb2c61539a Mon Sep 17 00:00:00 2001
+From: Michael Schroeder <mls@suse.de>
+Date: Mon, 14 Dec 2020 11:12:00 +0100
+Subject: [PATCH] testcase_read: error out if repos are added or the system is
+ changed too late
+
+We must not add new solvables after the considered map was created, the solver
+was created, or jobs were added. We may not changed the system after jobs have
+been added.
+
+(Jobs may point inside the whatproviedes array, so we must not invalidate this
+area.)
+---
+ ext/testcase.c | 21 +++++++++++++++++++++
+ 1 file changed, 21 insertions(+)
+
+diff --git a/ext/testcase.c b/ext/testcase.c
+index bd0643a8a..b81834faa 100644
+--- a/ext/testcase.c
++++ b/ext/testcase.c
+@@ -1975,6 +1975,7 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
+   Id *genid = 0;
+   int ngenid = 0;
+   Queue autoinstq;
++  int oldjobsize = job ? job->count : 0;
+ 
+   if (resultp)
+     *resultp = 0;
+@@ -2049,6 +2050,21 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
+ 	  int prio, subprio;
+ 	  const char *rdata;
+ 
++	  if (pool->considered)
++	    {
++	      pool_error(pool, 0, "testcase_read: cannot add repos after packages were disabled");
++	      continue;
++	    }
++	  if (solv)
++	    {
++	      pool_error(pool, 0, "testcase_read: cannot add repos after the solver was created");
++	      continue;
++	    }
++	  if (job && job->count != oldjobsize)
++	    {
++	      pool_error(pool, 0, "testcase_read: cannot add repos after jobs have been created");
++	      continue;
++	    }
+ 	  prepared = 0;
+           if (!poolflagsreset)
+ 	    {
+@@ -2109,6 +2125,11 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
+ 	  int i;
+ 
+ 	  /* must set the disttype before the arch */
++	  if (job && job->count != oldjobsize)
++	    {
++	      pool_error(pool, 0, "testcase_read: cannot change the system after jobs have been created");
++	      continue;
++	    }
+ 	  prepared = 0;
+ 	  if (strcmp(pieces[2], "*") != 0)
+ 	    {
diff --git a/SPECS/libsolv.spec b/SPECS/libsolv.spec
index 46a0794..df4bab2 100644
--- a/SPECS/libsolv.spec
+++ b/SPECS/libsolv.spec
@@ -43,7 +43,7 @@
 
 Name:           lib%{libname}
 Version:        0.7.16
-Release:        2%{?commit:.git.%{commitnum}.%{?shortcommit}}%{?dist}
+Release:        3%{?commit:.git.%{commitnum}.%{?shortcommit}}%{?dist}
 Summary:        Package dependency solver
 
 License:        BSD
@@ -55,6 +55,7 @@ Source:         %{url}/archive/%{version}/%{name}-%{version}.tar.gz
 %endif
 # https://bugzilla.redhat.com/show_bug.cgi?id=1630300
 Patch1:         0001-Add-support-for-computing-hashes-using-OpenSSL.patch
+Patch2:         0002-testcase_read-error-out-if-repos-are-added-or-the-system-is-changed-too-late.patch 
 
 BuildRequires:  cmake
 BuildRequires:  gcc-c++
@@ -299,6 +300,9 @@ Python 3 version.
 %endif
 
 %changelog
+* Mon Sep 27 2021 Pavla Kratochvilova <pkratoch@redhat.org> - 0.7.11-3
+- Backport patch: testcase_read: error out if repos are added or the system is changed too late
+
 * Thu Jan 14 2021 Nicola Sella <nsella@redhat.com> - 0.7.16-2
 - Enable zstd compression in libsolv