nebius/SWE-bench-extra huggingface dataset:
Repository: kjd/idna

Issue:
[Uncaught exception] UnicodeDecodeError when calling decode with arbitrary data
Hey,

I was doing some fuzzing and I found out that the `idna.decode()` method can raise a `UnicodeDecodeError` leading to a crash of the running program.

This could be problematic if users of the library are dealing with untrusted data since this issue will lead to a DoS. This should be detected and an `idna.IDNAError` should be triggered as detailed in the Readme [Exception](https://github.com/kjd/idna#exceptions) section.

# Reproduction

``` python
import idna

idna.decode(b'\x8d\xd2')
```

# Traceback

``` sh
python3 replay_crash.py
Traceback (most recent call last):
  File "replay_crash.py", line 3, in <module>
    idna.decode(b'\x8d\xd2')
  File "/home/scop/.local/lib/python3.8/site-packages/idna/core.py", line 387, in decode
    s = s.decode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8d in position 0: ordinal not in range(128)
```

Happy to help if you have any questions ;)

Comments:

Patch:
diff --git a/idna/core.py b/idna/core.py
index d605129..871ebd3 100644
--- a/idna/core.py
+++ b/idna/core.py
@@ -383,8 +383,11 @@ def encode(s, strict=False, uts46=False, std3_rules=False, transitional=False):
 
 def decode(s, strict=False, uts46=False, std3_rules=False):
     # type: (Union[str, bytes, bytearray], bool, bool, bool) -> str
-    if isinstance(s, (bytes, bytearray)):
-        s = s.decode('ascii')
+    try:
+        if isinstance(s, (bytes, bytearray)):
+            s = s.decode('ascii')
+    except UnicodeDecodeError:
+        raise IDNAError('Invalid ASCII in A-label')
     if uts46:
         s = uts46_remap(s, std3_rules, False)
     trailing_dot = False


Test patch:
diff --git a/tests/test_idna.py b/tests/test_idna.py
index 9e1d2d9..7ac6057 100755
--- a/tests/test_idna.py
+++ b/tests/test_idna.py
@@ -259,6 +259,7 @@ class IDNATests(unittest.TestCase):
         self.assertRaises(idna.IDNAError, idna.decode, 'XN---------90GGLBAGAAC.AA')
         self.assertRaises(idna.IDNAError, idna.decode, 'xn---------90gglbagaac.aa')
         self.assertRaises(idna.IDNAError, idna.decode, 'xn--')
+        self.assertRaises(idna.IDNAError, idna.decode, b'\x8d\xd2')
 
 if __name__ == '__main__':
     unittest.main()
Repository: kjd/idna

Issue:
IndexError with new trailing hyphen check
#64 introduced the following uncaught exception. Is this intended?

```python
>>> idna.ulabel('xn--')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/John/.pyenv/versions/3.6.5/Python.framework/Versions/3.6/lib/python3.6/site-packages/idna/core.py", line 303, in ulabel
    if label.decode('ascii')[-1] == '-':
IndexError: string index out of range
```

I would've expected `UnicodeError` or `IDNAError`, which are more descriptive.

Comments:

Patch:
diff --git a/idna/core.py b/idna/core.py
index b861d14..2c193d6 100644
--- a/idna/core.py
+++ b/idna/core.py
@@ -296,6 +296,8 @@ def ulabel(label):
     label = label.lower()
     if label.startswith(_alabel_prefix):
         label = label[len(_alabel_prefix):]
+        if not label:
+            raise IDNAError('Malformed A-label, no Punycode eligible content found')
         if label.decode('ascii')[-1] == '-':
             raise IDNAError('A-label must not end with a hyphen')
     else:


Test patch:
diff --git a/tests/test_idna.py b/tests/test_idna.py
index b62b9c6..9e1d2d9 100755
--- a/tests/test_idna.py
+++ b/tests/test_idna.py
@@ -258,6 +258,7 @@ class IDNATests(unittest.TestCase):
                          '\u0521\u0525\u0523-\u0523\u0523-----\u0521\u0523\u0523\u0523.aa')
         self.assertRaises(idna.IDNAError, idna.decode, 'XN---------90GGLBAGAAC.AA')
         self.assertRaises(idna.IDNAError, idna.decode, 'xn---------90gglbagaac.aa')
+        self.assertRaises(idna.IDNAError, idna.decode, 'xn--')
 
 if __name__ == '__main__':
     unittest.main()
Repository: klen/peewee_migrate

Issue:
Bug report: Self foreign keys are not handled
**Describe the bug**
After creating the migration with the model containing foreign key to itself, migration is failing due to `KeyError`. After quick investigation, the exact line containing the bug is `ForeignKeyField(model=migrator.orm["model"], ...)`. During execution of this code, `"model"` is not yet added to `migrator.orm` dict. Instead, the call should look like: `ForeignKeyField(model="self", ...)`. After changing it the proposed way, migration has completed successfully.

**To Reproduce**
Steps to reproduce the behavior:
1. Write a model containing a self-referencing foreign key:
```python
class TestModel(Model):
    parent = ForeignKeyField("self")
```
2. Create a migration
3. Run the migration

**Expected behavior**
Migration should pass correctly.

**Desktop (please complete the following information):**
 - Version 1.4.2


Comments:

Patch:
diff --git a/peewee_migrate/auto.py b/peewee_migrate/auto.py
index cab9f2a..a71ff4b 100644
--- a/peewee_migrate/auto.py
+++ b/peewee_migrate/auto.py
@@ -67,7 +67,11 @@ class Column(VanilaColumn):
         if isinstance(field, pw.ForeignKeyField):
             self.to_field = field.rel_field.name
             self.related_name = field.backref
-            self.rel_model = "migrator.orm['%s']" % field.rel_model._meta.table_name
+            self.rel_model = (
+                "'self'"
+                if field.rel_model == field.model
+                else "migrator.orm['%s']" % field.rel_model._meta.table_name
+            )
 
     def get_field(self, space=' '):
         # Generate the field definition for this column.


Test patch:
diff --git a/tests/test_auto.py b/tests/test_auto.py
index 5123aa5..2065bc8 100644
--- a/tests/test_auto.py
+++ b/tests/test_auto.py
@@ -95,3 +95,28 @@ def test_auto_multi_column_index():
     code = model_to_code(Object)
     assert code
     assert "indexes = [(('first_name', 'last_name'), True)]" in code
+
+
+def test_self_referencing_foreign_key_on_model_create():
+    from peewee_migrate.auto import field_to_code
+
+    class Employee(pw.Model):
+        manager = pw.ForeignKeyField("self")
+
+    code = field_to_code(Employee.manager)
+    assert "model='self'" in code
+
+
+def test_self_referencing_foreign_key_on_field_added():
+    from peewee_migrate.auto import diff_one
+
+    class Employee(pw.Model):
+        name = pw.CharField()
+
+    class EmployeeNew(pw.Model):
+        name = pw.CharField()
+        manager = pw.ForeignKeyField("self")
+
+    changes = diff_one(EmployeeNew, Employee)
+    assert "migrator.add_fields" in changes[0]
+    assert "model='self'" in changes[0]