internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: secdev/scapy

Issue:
WARNING: Calling str(pkt) on Python 3 makes no sense!
### Brief description

from scapy.all import *

ip_obj = IP()
tcp_obj = TCP()

when i debug this simple code, it says:

WARNING: Calling str(pkt) on Python 3 makes no sense!
WARNING: Calling str(pkt) on Python 3 makes no sense!
WARNING: Calling str(pkt) on Python 3 makes no sense!

how to fix this, please

### Scapy version

last

### Python version

last

### Operating system

last

### Additional environment information

no

### How to reproduce

from scapy.all import *

ip_obj = IP()
tcp_obj = TCP()

when i debug this simple code, it says:

WARNING: Calling str(pkt) on Python 3 makes no sense!
WARNING: Calling str(pkt) on Python 3 makes no sense!
WARNING: Calling str(pkt) on Python 3 makes no sense!

how to fix this, please

### Actual result

wrong

### Expected result

_No response_

### Related resources

no


Discussion:
Please read the documentarion and ask your questions on gitter. This is a bug tracker not a forum.
Where in the documentation is this? A browser keyword search on several relevant pages, and using the docs' pages search function didn't turn up a result. [For example, the API page on `packet`](https://scapy.readthedocs.io/en/latest/api/scapy.packet.html).
> Please read the documentarion and ask your questions on gitter. This is a bug tracker not a forum.

What do you think this is?
I think the problem is scapy intended usage is commandline as opposed to inside IDE and assumes you are consciously calling str() on packets. But PyCharm for example calls str() automatically when debugging to show all local variable contents. You can disable this behavior in "Debug toolbar | Settings | Variables Loading Policy" but of course that's not a good solution because you will now be debugging blind.

Resolving patch:
diff --git a/scapy/packet.py b/scapy/packet.py
--- a/scapy/packet.py
+++ b/scapy/packet.py
@@ -582,8 +582,7 @@ def __str__(self):
     else:
         def __str__(self):
             # type: () -> str
-            warning("Calling str(pkt) on Python 3 makes no sense!")
-            return str(self.build())
+            return self.summary()
 
     def __bytes__(self):
         # type: () -> bytes


Test patch:
Repository: secdev/scapy

Issue:
hexdiff() crashes with a smaller input
The following example make Scapy fail:
```
>>> hexdiff(IP()/TCP(), b"aaa")
```

I will provide a fix.


Discussion:

Resolving patch:
diff --git a/scapy/utils.py b/scapy/utils.py
--- a/scapy/utils.py
+++ b/scapy/utils.py
@@ -455,7 +455,7 @@ def hexdiff(a, b, autojunk=False):
 
         cl = ""
         for j in range(16):
-            if i + j < btx_len:
+            if i + j < min(len(backtrackx), len(backtracky)):
                 if line[j]:
                     col = colorize[(linex[j] != liney[j]) * (doy - dox)]
                     print(col("%02X" % orb(line[j])), end=' ')


Test patch:
diff --git a/test/regression.uts b/test/regression.uts
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -772,6 +772,11 @@ assert ret1 != ret2
 assert expected_ret1 in ret1
 assert expected_ret2 in ret2
 
+# Test corner cases that should not crash
+
+hexdiff(b"abc", IP() / TCP())
+hexdiff(IP() / TCP(), b"abc")
+
 = Test mysummary functions - Ether
 
 p = Ether(dst="ff:ff:ff:ff:ff:ff", src="ff:ff:ff:ff:ff:ff", type=0x9000)
Repository: secdev/scapy

Issue:
`RawPcapReader` is missing `__enter__` method
### Brief description

Hi,

On version 2.4.4., the `scapy.utils.RawPcapReader` class supported the `__enter__` context manager method, but in 2.4.5, that method was moved [from `RawPcapReader`](https://github.com/secdev/scapy/commit/fdded351f3c50236a1e43194df5dd8c6dbe92084#diff-7e53ee1d39af61ab3112ba2d0a9d80a60ad922575a8091f889c19ea7b2621eddL1284-L1287) to the [`PcapReader` subclass](https://github.com/secdev/scapy/commit/fdded351f3c50236a1e43194df5dd8c6dbe92084#diff-7e53ee1d39af61ab3112ba2d0a9d80a60ad922575a8091f889c19ea7b2621eddR1336-R1339). This breaks a portion of our code which uses a `RawPcapReader` in a `with` statement block.

### Scapy version

2.4.5

### Python version

3.6.9

### Operating system

MacOS 13.2.1

### Additional environment information

_No response_

### How to reproduce

```(python)
with RawPcapReader(some_pcap_file) as reader:
    # do something with the packets, e.g.:
    first_packet = next(reader, None)
``` 

### Actual result

```
AttributeError: __enter__
```

### Expected result

Successful processing of pcap.

### Related resources

_No response_


Discussion:

Resolving patch:
diff --git a/scapy/utils.py b/scapy/utils.py
--- a/scapy/utils.py
+++ b/scapy/utils.py
@@ -1256,6 +1256,10 @@ def __init__(self, filename, fdesc=None, magic=None):  # type: ignore
         self.linktype = linktype
         self.snaplen = snaplen
 
+    def __enter__(self):
+        # type: () -> RawPcapReader
+        return self
+
     def __iter__(self):
         # type: () -> RawPcapReader
         return self


Test patch:
diff --git a/test/regression.uts b/test/regression.uts
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -2238,6 +2238,19 @@ assert len([p for p in RawPcapReader(fd)]) == 1
 for (x, y) in RawPcapReader(fd):
     pass
 
+= Check RawPcapReader with a Context Manager
+~ pcap
+
+filename = get_temp_file(fd=False)
+wrpcap(filename, [IP()/TCP(), IP()/UDP()])
+
+try:
+    with RawPcapReader(filename) as reader:
+        packet = next(reader, None)
+    assert True
+except TypeError:
+    assert False
+
 = Check RawPcapWriter
 ~ pcap
Repository: secdev/scapy

Issue:
VLAN tag has incorrect field name
### Brief description

The 802.1Q VLAN tag object (`Dot1Q`) has an incorrectly-named field.  According to the IEEE specs, the fields are PCP, DEI, and VID.  Scapy uses `prio` and `vlan` for PCP and VID, which are reasonable.  But the DEI bit is called `id`, which is incorrect and could be confused for the VLAN ID `vlan`.  So, `id` should probably be renamed either `drop` or `dei` as the meaning of the bit is "drop eligible indicator".  For reference, wireshark decodes the fields in the UI as "PRI" or "Priority", "DEI", and "ID".

### Scapy version

2.4.4

### Python version

3.10

### Operating system

Arch Linux

### Additional environment information

_No response_

### How to reproduce

N/A

### Actual result

_No response_

### Expected result

_No response_

### Related resources

_No response_


Discussion:

Resolving patch:
diff --git a/scapy/layers/l2.py b/scapy/layers/l2.py
--- a/scapy/layers/l2.py
+++ b/scapy/layers/l2.py
@@ -371,9 +371,12 @@ class Dot1Q(Packet):
     name = "802.1Q"
     aliastypes = [Ether]
     fields_desc = [BitField("prio", 0, 3),
-                   BitField("id", 0, 1),
+                   BitField("dei", 0, 1),
                    BitField("vlan", 1, 12),
                    XShortEnumField("type", 0x0000, ETHER_TYPES)]
+    deprecated_fields = {
+        "id": ("dei", "2.5.0"),
+    }
 
     def answers(self, other):
         # type: (Packet) -> int


Test patch:
Repository: secdev/scapy

Issue:
Counter64 missing for ASN1 and BER
### Brief description

It looks like Counter64 value type was added years ago but at some point was taken out.
It was previously in https://github.com/secdev/scapy/commit/2e776b7917d60e640d15e4d4fb3015217443b233

### Scapy version

2.5

### Python version

3.12

### Operating system

Windows

### Additional environment information

_No response_

### How to reproduce

Receive a V2c SNMP packet containing a Counter64 value

### Actual result

_No response_

### Expected result

_No response_

### Related resources

_No response_


Discussion:

Resolving patch:
diff --git a/scapy/asn1/asn1.py b/scapy/asn1/asn1.py
--- a/scapy/asn1/asn1.py
+++ b/scapy/asn1/asn1.py
@@ -275,6 +275,7 @@ class ASN1_Class_UNIVERSAL(ASN1_Class):
     BMP_STRING = cast(ASN1Tag, 30)
     IPADDRESS = cast(ASN1Tag, 0 | 0x40)     # application-specific encoding
     COUNTER32 = cast(ASN1Tag, 1 | 0x40)     # application-specific encoding
+    COUNTER64 = cast(ASN1Tag, 6 | 0x40)     # application-specific encoding
     GAUGE32 = cast(ASN1Tag, 2 | 0x40)       # application-specific encoding
     TIME_TICKS = cast(ASN1Tag, 3 | 0x40)    # application-specific encoding
 
@@ -726,6 +727,10 @@ class ASN1_COUNTER32(ASN1_INTEGER):
     tag = ASN1_Class_UNIVERSAL.COUNTER32
 
 
+class ASN1_COUNTER64(ASN1_INTEGER):
+    tag = ASN1_Class_UNIVERSAL.COUNTER64
+
+
 class ASN1_GAUGE32(ASN1_INTEGER):
     tag = ASN1_Class_UNIVERSAL.GAUGE32
 
diff --git a/scapy/asn1/ber.py b/scapy/asn1/ber.py
--- a/scapy/asn1/ber.py
+++ b/scapy/asn1/ber.py
@@ -696,6 +696,10 @@ class BERcodec_COUNTER32(BERcodec_INTEGER):
     tag = ASN1_Class_UNIVERSAL.COUNTER32
 
 
+class BERcodec_COUNTER64(BERcodec_INTEGER):
+    tag = ASN1_Class_UNIVERSAL.COUNTER64
+
+
 class BERcodec_GAUGE32(BERcodec_INTEGER):
     tag = ASN1_Class_UNIVERSAL.GAUGE32
 


Test patch:
diff --git a/test/regression.uts b/test/regression.uts
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -1528,7 +1528,7 @@ o
 assert o in [
     b'\x1e\x023V',  # PyPy 2.7
     b'A\x02\x07q',  # Python 2.7
-    b'B\x02\xfe\x92',  # python 3.7-3.9
+    b'F\x02\xfe\x92',   # python 3.7-3.9
 ]
 
 = ASN1 - ASN1_BIT_STRING
Repository: secdev/scapy

Issue:
Incorrect RTCP SR + RR parsing
### Brief description

The RTCP parser fails to handle a packet that contains both Sender Report and Received Report, which is is the most common data for a two-way session.

It seems that the "sender_info" info contain a payload, this should be parsed as a ReceptionReport info

Incorrect behavior demonstrated in UTS here: https://github.com/secdev/scapy/commit/0bb9db2932d91d2f6e057caea60db78a2ad54f96

### Scapy version

main

### Python version

3.10

### Operating system

Linux 5.15.146

### Additional environment information

_No response_

### How to reproduce

Run tests on provided branch:

`test/run_tests  -P "load_contrib('rtcp')" -t test/contrib/rtcp.uts -F`



### Actual result

Demo test should fail.

ReceptionReport after SenderInfo should be parsed. SenderInfo should never have a payload, it's a fixed-sized struct

### Expected result

The commented asserts should pass instead

### Related resources

https://datatracker.ietf.org/doc/html/rfc3550


Discussion:
@oborichkin 

Resolving patch:
diff --git a/scapy/contrib/rtcp.py b/scapy/contrib/rtcp.py
--- a/scapy/contrib/rtcp.py
+++ b/scapy/contrib/rtcp.py
@@ -51,6 +51,9 @@ class SenderInfo(Packet):
         IntField('sender_octet_count', None)
     ]
 
+    def extract_padding(self, p):
+        return "", p
+
 
 class ReceptionReport(Packet):
     name = "Reception report"
@@ -64,6 +67,9 @@ class ReceptionReport(Packet):
         IntField('delay_since_last_SR', None)
     ]
 
+    def extract_padding(self, p):
+        return "", p
+
 
 _sdes_chunk_types = {
     0: "END",


Test patch:
diff --git a/test/contrib/rtcp.uts b/test/contrib/rtcp.uts
--- a/test/contrib/rtcp.uts
+++ b/test/contrib/rtcp.uts
@@ -76,3 +76,23 @@ raw = b"\x81\xc9\x00\x07\xa2\xdf\x02\x72\x49\x6e\x93\xbd\x00\xff\xff\xff" \
       b"\x30\x33\x34\x38\x38\x39\x30\x31\x40\x68\x6f\x73\x74\x2d\x65\x37" \
       b"\x32\x64\x62\x34\x33\x64\x06\x09\x47\x53\x74\x72\x65\x61\x6d\x65" \
       b"\x72\x00\x00\x00"
+
+= format SR + 2xRR and parse back
+
+rtcp = RTCP()
+rtcp.packet_type = 200
+rtcp.sourcesync = 0x01010101
+rtcp.sender_info.rtp_timestamp = 0x03030303
+rtcp.count = 2
+rtcp.report_blocks.append(ReceptionReport(sourcesync=0x04040404))
+rtcp.report_blocks.append(ReceptionReport(sourcesync=0x05050505))
+b = bytes(rtcp)
+rtcp2 = RTCP(b)
+assert rtcp2.count == 2
+assert rtcp2.length == 18
+assert rtcp2.sourcesync == 0x01010101
+assert rtcp2.sender_info.rtp_timestamp == 0x03030303
+assert len(rtcp2.sender_info.payload) == 0
+assert rtcp2.report_blocks[0].sourcesync == 0x04040404
+assert len(rtcp2.report_blocks[0].payload) == 0
+assert rtcp2.report_blocks[1].sourcesync == 0x05050505
Repository: secdev/scapy

Issue:
Scapy overides platform
Scapy exports the platform name, and could override the platform module. This is likely the issue: https://github.com/secdev/scapy/blob/b0506a1e22321eba41d5c21d26bba418de04bc8f/scapy/consts.py#L10

Here are the example:

```shell
python issue.py 
<class 'str'>
<class 'module'>
```

```python
import platform
from scapy.all import *
print(type(platform))

import platform
print(type(platform))
```


Discussion:
Good catch. We should probably add an `__all__` to it.

Resolving patch:
diff --git a/scapy/consts.py b/scapy/consts.py
--- a/scapy/consts.py
+++ b/scapy/consts.py
@@ -10,6 +10,20 @@
 from sys import byteorder, platform, maxsize
 import platform as platform_lib
 
+__all__ = [
+    "LINUX",
+    "OPENBSD",
+    "FREEBSD",
+    "NETBSD",
+    "DARWIN",
+    "SOLARIS",
+    "WINDOWS",
+    "WINDOWS_XP",
+    "BSD",
+    "IS_64BITS",
+    "BIG_ENDIAN",
+]
+
 LINUX = platform.startswith("linux")
 OPENBSD = platform.startswith("openbsd")
 FREEBSD = "freebsd" in platform


Test patch:
Repository: uclouvain/osis-portal

Issue:
Bug with internship id when trying to access internship selection
Bug reported by sentry and blocking students from choosing an internship.



Discussion:

Resolving patch:
diff --git a/internship/views/main.py b/internship/views/main.py
--- a/internship/views/main.py
+++ b/internship/views/main.py
@@ -78,11 +78,12 @@ def view_internship_home(request, cohort_id):
 @redirect_if_subscription_not_allowed
 @permission_required('internship.can_access_internship', raise_exception=True)
 def view_internship_selection(request, cohort_id, internship_id=-1, speciality_id=-1):
+    cohort = mdl_internship.cohort.Cohort.objects.get(pk=cohort_id)
     if int(internship_id) < 1:
-        return redirect(view_internship_selection, cohort_id=cohort_id, internship_id=1)
+        current_internship = mdl_internship.internship.Internship.objects.filter(cohort=cohort).first()
+        return redirect(view_internship_selection, cohort_id=cohort_id, internship_id=current_internship.id)
 
     student            = mdl_base.student.find_by_user(request.user)
-    cohort             = mdl_internship.cohort.Cohort.objects.get(pk=cohort_id)
     internships        = mdl_internship.internship.Internship.objects.filter(cohort=cohort)
     current_internship = internships.get(pk=internship_id)
     specialities       = mdl_internship.internship_speciality.filter_by_cohort(cohort)
@@ -98,7 +99,7 @@ def view_internship_selection(request, cohort_id, internship_id=-1, speciality_i
 
     if current_internship.speciality != None:
         speciality = current_internship.speciality
-        selectable_offers = mdl_internship.internship_offer.InternshipOffer.objects.filter(internship=current_internship, cohort=cohort)
+        selectable_offers = mdl_internship.internship_offer.InternshipOffer.objects.filter(internship=current_internship, cohort=cohort).order_by("organization__reference")
     else:
         speciality = specialities.filter(pk=speciality_id).first()
         selectable_offers = mdl_internship.internship_offer.find_selectable_by_speciality_and_cohort(speciality=speciality, cohort=cohort)


Test patch:
Repository: uclouvain/osis-portal

Issue:
Bug when multilple students try to insert internship choices
Major issue preventing students from encoding choices :'(



Discussion:

Resolving patch:
diff --git a/internship/views/main.py b/internship/views/main.py
--- a/internship/views/main.py
+++ b/internship/views/main.py
@@ -87,7 +87,7 @@ def view_internship_selection(request, cohort_id, internship_id=-1, speciality_i
     internships        = mdl_internship.internship.Internship.objects.filter(cohort=cohort)
     current_internship = internships.get(pk=internship_id)
     specialities       = mdl_internship.internship_speciality.filter_by_cohort(cohort)
-    internship_choices = mdl_internship.internship_choice.InternshipChoice.objects.filter(speciality_id__in=specialities, internship=current_internship)
+    internship_choices = mdl_internship.internship_choice.InternshipChoice.objects.filter(speciality_id__in=specialities, internship=current_internship, student=student)
     current_choice     = internship_choices.filter(internship=current_internship).first()
 
     is_open = mdl_internship.internship_offer.get_number_selectable(cohort) > 0


Test patch:
Repository: uclouvain/osis-portal

Issue:
Fix student scope
Fixes #1018 



Discussion:

Resolving patch:
diff --git a/internship/views/main.py b/internship/views/main.py
--- a/internship/views/main.py
+++ b/internship/views/main.py
@@ -87,7 +87,7 @@ def view_internship_selection(request, cohort_id, internship_id=-1, speciality_i
     internships        = mdl_internship.internship.Internship.objects.filter(cohort=cohort)
     current_internship = internships.get(pk=internship_id)
     specialities       = mdl_internship.internship_speciality.filter_by_cohort(cohort)
-    internship_choices = mdl_internship.internship_choice.InternshipChoice.objects.filter(speciality_id__in=specialities, internship=current_internship)
+    internship_choices = mdl_internship.internship_choice.InternshipChoice.objects.filter(speciality_id__in=specialities, internship=current_internship, student=student)
     current_choice     = internship_choices.filter(internship=current_internship).first()
 
     is_open = mdl_internship.internship_offer.get_number_selectable(cohort) > 0


Test patch:
Repository: uclouvain/osis-portal

Issue:
Show offers without a master in internship
At the moment we only show offers with a master.



Discussion:

Resolving patch:
diff --git a/internship/models/internship_offer.py b/internship/models/internship_offer.py
--- a/internship/models/internship_offer.py
+++ b/internship/models/internship_offer.py
@@ -57,10 +57,10 @@ class Meta:
 
 
 def find_selectable_by_speciality_and_cohort(speciality, cohort):
-    return InternshipOffer.objects.filter(speciality=speciality, cohort=cohort, internship=None, selectable=True, master__isnull=False).order_by("organization__reference")
+    return InternshipOffer.objects.filter(speciality=speciality, cohort=cohort, internship=None, selectable=True).order_by("organization__reference")
 
 def find_selectable_by_cohort(cohort):
-    return InternshipOffer.objects.filter(cohort=cohort, internship=None, selectable=True, master__isnull=False).order_by("organization__reference")
+    return InternshipOffer.objects.filter(cohort=cohort, internship=None, selectable=True).order_by("organization__reference")
 
 def find_by_speciality(speciality):
     return InternshipOffer.objects.filter(speciality=speciality)
diff --git a/internship/views/main.py b/internship/views/main.py
--- a/internship/views/main.py
+++ b/internship/views/main.py
@@ -99,7 +99,7 @@ def view_internship_selection(request, cohort_id, internship_id=-1, speciality_i
 
     if current_internship.speciality != None:
         speciality = current_internship.speciality
-        selectable_offers = mdl_internship.internship_offer.InternshipOffer.objects.filter(internship=current_internship, cohort=cohort, selectable=True, master__isnull=False).order_by("organization__reference")
+        selectable_offers = mdl_internship.internship_offer.InternshipOffer.objects.filter(internship=current_internship, cohort=cohort, selectable=True).order_by("organization__reference")
     else:
         speciality = specialities.filter(pk=speciality_id).first()
         non_mandatory_offers = mdl_internship.internship_offer.find_selectable_by_cohort(cohort=cohort)


Test patch:
Repository: uclouvain/osis-portal

Issue:
Fix sorting in internship selection
- Liste des spécialité dans les stages aux choix doivent être triées par ordre alphabétique
- Liste des stages obligatoires doit être triée par ordre alphabétique
- Les stages au choix doivent apparaître après les stages obligatoires


Discussion:

Resolving patch:
diff --git a/internship/views/main.py b/internship/views/main.py
--- a/internship/views/main.py
+++ b/internship/views/main.py
@@ -84,9 +84,9 @@ def view_internship_selection(request, cohort_id, internship_id=-1, speciality_i
         return redirect(view_internship_selection, cohort_id=cohort_id, internship_id=current_internship.id)
 
     student            = mdl_base.student.find_by_user(request.user)
-    internships        = mdl_internship.internship.Internship.objects.filter(cohort=cohort)
+    internships        = mdl_internship.internship.Internship.objects.filter(cohort=cohort).order_by("speciality__name", "name")
     current_internship = internships.get(pk=internship_id)
-    specialities       = mdl_internship.internship_speciality.filter_by_cohort(cohort)
+    specialities       = mdl_internship.internship_speciality.filter_by_cohort(cohort).order_by("name")
     internship_choices = mdl_internship.internship_choice.InternshipChoice.objects.filter(speciality_id__in=specialities, internship=current_internship, student=student)
     current_choice     = internship_choices.filter(internship=current_internship).first()
 
@@ -105,7 +105,7 @@ def view_internship_selection(request, cohort_id, internship_id=-1, speciality_i
         non_mandatory_offers = mdl_internship.internship_offer.find_selectable_by_cohort(cohort=cohort)
         selectable_offers = mdl_internship.internship_offer.find_selectable_by_speciality_and_cohort(speciality=speciality, cohort=cohort)
         speciality_ids = non_mandatory_offers.values_list("speciality_id", flat=True)
-        specialities = specialities.filter(id__in=speciality_ids)
+        specialities = specialities.filter(id__in=speciality_ids).order_by("name")
 
     offer_preference_formset = formset_factory(OfferPreferenceForm, formset=OfferPreferenceFormSet,
                                             extra=len(selectable_offers), min_num=len(selectable_offers),


Test patch:
Repository: DataBiosphere/toil

Issue:
Make Jenkins deploy to PyPI



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@
 
 setup(
     name='toil',
-    version='3.0.3.dev6',
+    version='3.0.4',
     description='Pipeline management software for clusters.',
     author='Benedict Paten',
     author_email='benedict@soe.usc.edu',


Test patch:
Repository: DataBiosphere/toil

Issue:
Jenkins should only deploy to PyPI when building off the master branch



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@
 
 setup(
     name='toil',
-    version='3.0.4',
+    version='3.0.5.dev1',
     description='Pipeline management software for clusters.',
     author='Benedict Paten',
     author_email='benedict@soe.usc.edu',


Test patch: